i have 3 images per direction of movement. i move with the WASD scheme.
i can only get my character to look as though i am moving in one direction can someone please help.
if someone can code out or just plain out give me hints or a direction to move in, so i can have 3 different images for up down left and right directions that would be insanely awesome.
oh btw i coded this by cutting out images i needed with gimp and labeling them player 0-2;
if someone can show me how to crop the images out from the sprite sheet with the processing language that would be cool too : )
my code is :
int numFrames = 3; // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
void setup()
{
size(800, 600);
frameRate(3);
images[0] = loadImage("player0.jpg");
for (int i=0; i<numFrames; i++) {
String imageName = "player" + nf(i,1) + ".jpg";
images[i] = loadImage(imageName);
}
}
void draw()
{
background(255);
player();
controls();
}
void player() {
image(images[frame], playerX, playerY);
}
int playerY=800/2;
int playerX=600/2;
void controls() {
if (keyPressed) {
if (key == 'w') {
playerY-=5;
}
if (key == 'a') {
playerX-=5;
}
if (key == 's') {
playerY+=5;
}
if (key == 'd') {
playerX+=5;
frame = (frame+1) % numFrames; // Use % to cycle through frames
}
}
}
sprite sheet:
thanks any help/suggestions will be very much appreciated!
1