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

2013/9/10

Need Help Animating Actor

Otaku_Programmer Otaku_Programmer

2013/9/10

#
private GreenfootImage image1; private GreenfootImage image2; public void animateCrab() { if ( getImage() == image1 ) { setImage(image2); } else { setImage(image1); } } This code used to animate the actor but at some point it stopped working. I have tried a dozen solutions and none have worked as of yet. Everything I have tried has just crashed the client by overusing memory.
danpost danpost

2013/9/10

#
The problem may not be with the code provided.
Otaku_Programmer Otaku_Programmer

2013/9/12

#
What is the problem then? That code has its own method. That method just sits there. What could be interfering?
MatheMagician MatheMagician

2013/9/12

#
You might need to change this:
if(getImage() == image1)
to this:
if(getImage().equals(image1))
Also, you might not be calling animateCrab() in the act method, which I believe is what danpost was referring to.
danpost danpost

2013/9/12

#
@MatheMagician, I think in this case, the usage of '==' should only return a possible false result one time (on the first act cycle the method is executed). After that, the image set will be the same instance of one of the two images saved in the fields and the condition will return an accurate true/false result.
MatheMagician MatheMagician

2013/9/13

#
I tested both of them and neither worked :( I think Otaku might have to use a boolean variable instead of a method.
danpost danpost

2013/9/13

#
We really do not have enough information to help at this point. Best might be to post the code for the whole class.
You need to login to post a reply.