Hello guys, this is my FIRST post on these forums!, just simply googled java programming forums and hey, here I am :), hope to stay, get information/help/tips, and also deal them.
Well my problem is with my new 2D java game, it’s very simple contains a background, the sprites for all types of character movement, that’s about it at the moment.
I have the basics setup, you know…
Draw the map background, draw the character, keyListeners, you know if left key is down than obviously the characters position would move absX–;, and than it will draw a new Sprite/ImageIcon which looks like one of these:
There are a total of six Sprites for when the character is walking down the screen, so here is where my problem/call for advice is coming into play:
I would like to post a couple of snippets first very brief, just showing you guys how the animation is being added at the moment.
The first snippet is coming from the keyPressed() method, for when the character is moving down:
if (i == 40) { //Down
downPressed = true;
if (h >= 300) { canMove = false; return; } //Stopping the character from going off the screen.
Sprite = walkFront1.getImage();
h++;
}
The method as you can see for grabbing the sprite is this “Sprite = walkFront1.getImage();”, which simply returns a ImageIcon and the path of the file.
The second method is the paint(Graphics g), which is located in the frames class.
(Note: the code shown was subtracted from the only contents are the ones for the movement down)
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(p.getImage(), p.absX, p.absY, null);
}
The p.getImage(), which is in the Player class, was defined earlier from the “Sprite = walkFront1.getImage();” + the path for the image.
So my question here is what would I have to do to add in a Animation process, 5-6+ steps, simply being called upon whenever the player is moving in that direction, possibly detecting as long as that key is held down, do that process.
I was thinking about creating a sub Thread, which would just simply sleep, detect what keys are held down and what are not, than do a animation, and loop through that until it the keyPressed was released.
I’m 17, and i’m just now starting to get serious about Java programming, possibly after my GED go into College or take further action into learning about it.
Please give me some feedback guys would be great.