This site requires JavaScript, please enable it in your browser!
Greenfoot back
A2O
A2O wrote ...

2015/12/4

Attack-animation

A2O A2O

2015/12/4

#
basically, I have this code for my chars attacks. now the problem is, that I cant get him being "Image3_right.png" at the end again. I mean. the moment he stops attacking, his Image should go to "Image3_right.png" again. I tried it with : if(!Greenfoot.isKeyDown("Y") { setImage("Image3_right.png"); } but u can see yourself why that wouldnt work :DD /** * */ public void shoot() { if(counter1 == 0) { if(Greenfoot.isKeyDown("Y")) { getWorld().addObject(new Shot(), getX(), getY());; setImage("Image3_right.png"); timer(1); } } counter1++; if(counter1>20) { counter1 = 0; } } int i=0; public void timer(int time) { i++; if(i==time) { setImage("Image3_shoot_right.png"); } if(i==time+1) { i=0; } }
danpost danpost

2015/12/4

#
First, you need to decide, one way or the other, what will determine the image to revert back. You could use the timer or you could use the release of the "Y" key. Then use only the one way. As far as the timer, you are attempting to run it deep inside the 'shoot' method, which means that it will only run when (a) counter1 == 0 and (b) Greenfoot.isKeyDown("Y") == true. For the 19 act cycles that the value of counter1 was not zero, the timer will not run. What I am getting at is that the timer must be executed outside any conditions that are required for shooting. If, instead of incrementing the timer to whatever time is, you set timer to time and decrement, then while positive, the alternate image is being shown; when the timer value is decreased from one to zero, change the image back; when the timer value is zero, check for shooting.
You need to login to post a reply.