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

2015/4/6

How I make my timer working

sun12 sun12

2015/4/6

#
protected long timeStarted = System.currentTimeMillis(); protected long currentTime = System.currentTimeMillis(); public EndBar() { barNum = 1; } public void act() { long elapsedTime = currentTime - timeStarted; if (elapsedTime / 1000 > 1) { timeStarted = currentTime; deplete(); } }
danpost danpost

2015/4/6

#
You need to show ALL code related to this EndBar object (all code in world, and other classes, for fielding, creating, and adding; and entire EndBar class)
sun12 sun12

2015/4/6

#
public class EndBar extends Actor { private int barNum; protected long timeStarted = System.currentTimeMillis(); protected long currentTime = System.currentTimeMillis(); public EndBar() { barNum = 1; } public void act() { long elapsedTime = currentTime - timeStarted; if (currentTime / 10000 > 1) { timeStarted = currentTime; System.out.println(timeStarted); deplete(); } } public void deplete() { if(barNum == 1) { setImage("25.png"); barNum++; } else if(barNum == 2) { setImage("50.png"); barNum++; } else if(barNum == 3) { setImage("75.png"); barNum++; } else if(barNum == 4) { setImage("100.png"); barNum = 0; } } I want to slow down the animation.
sun12 sun12

2015/4/6

#
Here is my world method public class LoserG extends TimeWorld { /** * Constructor for objects of class LoserG. * */ public LoserG() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 600, 1); super.act(); addObject(new EndBar(), 425,521); }
sun12 sun12

2015/4/6

#
public class TimeWorld extends World { protected long currentTime; public static Customers customer; /** * Constructor for objects of class TimeWorld. * */ public TimeWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. this(600, 400, 1); } public TimeWorld(int x, int y, int c) { super(x,y,c); addObject(new Score(), 640, 35); GreenfootSound sound; sound = new GreenfootSound("always.wav"); sound.play(); } public void act() { currentTime = System.currentTimeMillis(); } public long getTime() { return currentTime; } }
danpost danpost

2015/4/6

#
To slow down the animation, divide 'elapsedTime' by 10000 instead of 'currentTime' in the 'act' method of the EndBar class.
sun12 sun12

2015/4/6

#
I did that and my bar is not moving anymore.
sun12 sun12

2015/4/6

#
I got it. Thank you for your help !!! :)
You need to login to post a reply.