Jump to content
  • Advertisement
Sign in to follow this  
xDancinpoptartx

Java game programing help.

This topic is 2502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
For sprites I use float variables dx and dy for "delta X" and "Delta Y' (change in x or y per second). So if I want it to move 100 pixels per second in the x direction then dx =100;

These numbers are always positive. I then have 2 int direction flags which are either +1 or -1. You could easily do the same thing by simply looking at whether or not dx and dy are positive or negative. I chose the direction flag because at the time it seemed an easy way to invert gravity and get things to bounce off of walls. I think I may have simply gone with positive or negative dx and dy if I was doing it again.)

In any case, you can check either your dx or direction flag to see which way the sprite is moving.

Now, I'm assuming that your question is "how do I know if I'm going left or right?" Or, is your question actually asking how to change the image of the sprite? For that we'd have to know a bit more about how you're constructing your sprite. Are you useing a strip of images for animation? Or do you just want one image if it's moving left and another if it's moving right?

There is some good information on sprites and side scrollers here: http://fivedots.coe.psu.ac.th/~ad/jg/ch06/index.html
and here: http://fivedots.coe.psu.ac.th/~ad/jg/ch062/index.html

Share this post


Link to post
Share on other sites
Greg_B points to a great resource but it might be a bit overwhelming if you have a completely different layout for your game. In plain simple English, what you want to is to have one Animation object for each direction. Upon the detection of a key press, simply swap that object for the current one being displayed. An Animation object should contain a series of images that represents the animation of w/e object in game you are trying to animate and play these images in a timely sequence.

CXD

Share this post


Link to post
Share on other sites
I am not trying to have a animation play i just want the image facing the direction you are moving, and thank you for the link it actually helped me solve another problem i was having.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!