Hi all,
So I have an object in Java with a sprite associated to it. I also have an array of 4 different PImages, and I want to gradually change the sprite of that object into each of the PImages in that array (technically “animating” the sprite"), and I want each sprite to last for 0.5 seconds.
Can anyone help me with this?
Here is my approach. These are all written in the draw() method. The object is the brickwall, and sprites is the array containing the sprite. Fireball hitting the brickwall is the trigger event.
wallcounter=0;
//when fireball hits wall, fireball disappears and wall is destroyed'
for(int i = 0; i < this.fireballs.size(); i++){
//detect collision between fireball and wall
for(int b = 0; b < this.brickwalls.size(); b++){
if((this.fireballs.get(i).getX() <= this.brickwalls.get(b).getX()+10 & this.fireballs.get(i).getX() >= this.brickwalls.get(b).getX()-10) &&
(this.fireballs.get(i).getY() <= this.brickwalls.get(b).getY()+10 & this.fireballs.get(i).getY() >= this.brickwalls.get(b).getY()-10)){
this.fireballs.remove(i);
if(wallcounter < 4 && wallcounter >= 0){
this.brickwalls.get(b).setSprite(sprites[0]);
wallcounter++;
}
else if(wallcounter >= 5 && wallcounter < 8){
this.brickwalls.get(b).setSprite(sprites[1]);
wallcounter++;
}
else if(wallcounter >= 8 && wallcounter <12){
this.brickwalls.get(b).setSprite(sprites[2]);
wallcounter++;
}else if(wallcounter >= 12 && wallcounter < 16){
this.brickwalls.get(b).setSprite(sprites[2]);
wallcounter++;
}
else{
this.brickwalls.remove(b);
wallcounter = 0;
}
if(i == this.fireballs.size()){
break;
}
if(b == this.brickwalls.size()){
break;
}
}
}
}