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


Gold shaking method

Hi guys, I am coding a digger game and I need help for the gold method. When there is no ground below the gold, the gold shakes and falls. I would like to make the gold shake for around 3 seconds instead of it executing straight away. if(earthBelow()) { animate(); } else { { animateShake(); } Thanks to anyone that can help
danpost danpost


Add an int timer field:
private int shakeTimer;
Then use something like this:
if (earthBelow())
    shakeTimer = 0;
    if (++shakeTimer > 180) fall();
    else animateShake();

You need to login to post a reply.