Hello,
maybe you save the images individually naming them 0..44.jpg or so.
All exact same size.
Now you have one array with two dimensions:
images [ typeOfMovement ][ frameNumber ]
for the 1st indexyou can use constants for the 1st index such as:
- final int typeOfMovementStand = 0;
- final int typeOfMovementDead = 1;
- final int typeOfMovementWalkLeft = 2;
- final int typeOfMovementWalkRight = 3;
- final int typeOfMovementWalkUp = 4;
- final int typeOfMovementWalkDown = 5;
- final int typeOfMovementFight = 6;
Load all images in the array using the constants.
set
- int typeOfMovementCurrent = typeOfMovementStand;
When you change
the direction of your player figure (when walking), in void controls()
change
- typeOfMovementCurrent = typeOfMovementWalkRight;
(e.g.) accordingly.
[[ remark: if you need it later :
you can use the constants in switch then etc. :
switch (typeOfMovementCurrent) {
case typeOfMovementStand:
...
break;
case typeOfMovementDead:
...
break;
......................
......................
.....................
default:
// do nothing
println("Error: shouldn't get here with " + typeOfMovementCurrent );
break;
}
]]
for the second indexwhile walking just do
- frameNumber ++;
- if (frameNumber > maxFrame) {
- frameNumber = 0;
- }
When maxFrame is not the same for all types of movement (I expect it'll be not the same),
have an extra list maxFrames [typeOfMovementCurrent] to store them individually.
- frameNumber ++;
- if (frameNumber > maxFrames[ typeOfMovementCurrent ]) {
- frameNumber = 0;
- }
etc.
Greetings, Chrisir
