• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sprite / Window Collision

 
Greenhorn
Posts: 20
Eclipse IDE Debian Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 41
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic