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

2021/6/9

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

2021/6/9

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

}
You need to login to post a reply.