aspose file tools*
The moose likes Game Development and the fly likes Sprite / Window Collision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Sprite / Window Collision" Watch "Sprite / Window Collision" New topic
Author

Sprite / Window Collision

Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

Hello all,

I know I post on here a lot but A: I have so many questions and B: This is best place for me to get help.

I currently have sprites working, I can move them around and stuff but I want to keep the sprite in the window, sort of like a border so the sprite cannot move outside of view.

I have already tried using a method called keepInView() and it basically got the x and y of the player entity and went kinda something like this:

But this didnt work....and I've tried playing around in the code and I've had no luck anywhere...

Here's my code for all 3 files so far:


Launcher.java :




Panel.java



Entity.java


Any help is greatly appreciated....

Also, where can I get some really good LWJGL tutorials? I'm going to try that once I have the hang of this
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3401
    
    9
Well, you haven't told us why your first attempt doesn't work. What's wrong with the keepInView() method, besides the fact that the lower border is incorrect?

More importantly though, I want to discourage the way you're drawing to the screen. You should be overriding JPanel's paintComponent() method instead. Take a close look at the following example:

Jj Hill
Ranch Hand

Joined: Jul 25, 2011
Posts: 41

I see no error in the keepInView method. At least not in the logic. Unless you aren't constantly calling keepInView. If you aren't constantly calling in(in the paintComponent() method) then it will stop, and keep on going.
 
Don't get me started about those stupid light bulbs.
 
subject: Sprite / Window Collision
 
Similar Threads
Graphics on Applets
Issue with graphics2d
Robot - can't get symbols: !@#$^&*()_+
KeyListener working randomly
Beginning Games