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

2017/12/8

I am trying to switch images at a slower pace, but whatever I put in the counter it doesn't work to slow the images down when switching

mouseofgory mouseofgory

2017/12/8

#
I tried putting the counter at 5, 100, 500 and it gives me the same results. What am I doing wrong? import greenfoot.*; /** * Write a description of class Home here. * * @author (your name) * @version (a version number or a date) */ public class Fire extends Actor { private GreenfootImage image1; private GreenfootImage image2; private int counter; private int actCounter; /** * Act - do whatever the Home wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Fire() { image1 = new GreenfootImage("fire-small.png"); image2 = new GreenfootImage("fire-big.png"); setImage(image1); } public void act() { switchImage(); counter++; if (counter == 3) { counter = 0; switchImage(); } } public void switchImage() { if (getImage() == image1 ) { setImage(image2); } else { setImage(image1); } // Add your action code here. } }
Super_Hippo Super_Hippo

2017/12/8

#
Remove the first line of your act method.
mouseofgory mouseofgory

2017/12/8

#
Thank you! Such an obvious mistake and I missed it!
You need to login to post a reply.