Jump to content

  • Log In with Google      Sign In   
  • Create Account

Java game programing help.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Dylan_DE   Members   -  Reputation: 131

Like
0Likes
Like

Posted 03 February 2012 - 09:08 AM

Ok, i got movement and a sprite. how do i move it right and it shows the right image and when i move it left it shows the image facing left and down and up?

Sponsor:

#2 Greg_B   Members   -  Reputation: 112

Like
0Likes
Like

Posted 06 February 2012 - 09:30 AM

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

#3 ChaoSXDemon   Members   -  Reputation: 96

Like
0Likes
Like

Posted 06 February 2012 - 05:44 PM

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
Youtube:
My Channel

Video Lessons:
Java Programming Lessons

Tutorials Written (Not-Active):
Introduction to A.I.

#4 Dylan_DE   Members   -  Reputation: 131

Like
0Likes
Like

Posted 07 February 2012 - 07:19 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS