1

Possible Duplicate:
jQuery/Javascript collision detection

I am learning how to code in JavaScript, and im using the jQuery library. I have a player that moves around the screen with the WASD keys. I want him to stop when he comes to the boundaries of the game. I am using two divs, one is called playground (the area where the game takes place) and another called player. I have them set up like this:

<div id="playground">
    <div id="player"></div>
</div>

The player moves great but I want him to stop when he gets to the edge of the playground. Please explain your answer in depth because I'm new to JavaScript programming. Any help would be much appreciated.

Community
  • 1
  • 1
corrigan_sam
  • 53
  • 2
  • 15

1 Answers1

0

So you need to use something like this:

 if (this.__move.left) {
      if (!this.isPlaying("walk_left"))
        this.stop().animate("walk_left", 10);
    }

here is a really good example and a demo. Try it http://craftyjs.com/demos/tutorial/tutorial.html

Ferdinand Beyer
  • 64,979
  • 15
  • 154
  • 145
user1529342
  • 354
  • 1
  • 2
  • 11
  • Thanks man, ill give this a try, bit confusing atm but im sure ill work it out :) How would i implement this into my code? Sorry for being a pain :0 – corrigan_sam Sep 22 '12 at 07:25
  • no worries .... when you find this is right please vote the answer... all the best – user1529342 Sep 22 '12 at 07:27
  • Cheers, I've already voted the answer, Thanks for the help, just wondering how i put this into the code, Where do i put my variables, Sorry to be a annoyance, Thanks in advance :) – corrigan_sam Sep 22 '12 at 07:32
  • Im Sorry but i cannot work this out, the website you linked is using a library called craft which i don't want to use, and it is to stop animation, is there any other way you know to stop the player on the boundary? – corrigan_sam Sep 22 '12 at 08:41