Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool java: collision listener for a game

    hey,

    i have been making very simple games for java for awhile now but i have come across yet another problem.

    all the games i made just had about 3 or 4 objects that needed collision detection... so i just put it in the while loop in the run() method of the applet.

    well that worked out fine but as i am getting more in to a more advanced game it is starting to get messy(and slower). i intend to have alot of collisions in this game. then i look at a game like mario 64 and think that they couldnt have checked for collisions in every step. so i figured there is some way to write a listener(like a mouse listener or a key listener) that could wait for some variables to equal something then trigger the action.

    i have searched far and wide(on the web..) for how to do this but i have found nothing.

    is the only way to detect collisions in an infinite loop or is there another way?

    thx

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whenever an object moves in the game that can collide with another, you should check for a collision. So whenever event invokes movement on such an object, you should check for a collision (for instance, if the player is moved by keys, you check the if the player has collided with anything).

    Hope that helps!

    Happy coding!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •