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

2020/11/10

how to add sound while moving the car

zimmy zimmy

2020/11/10

#
eatcoins(); if(Greenfoot.isKeyDown("up")) setLocation(getX() , getY()-3 ); if(Greenfoot.isKeyDown("right")) setLocation(getX() +3 , getY()); if(Greenfoot.isKeyDown("left")) setLocation(getX() -3 , getY()); } public void eatcoins() { Actor coins = getOneIntersectingObject(coins.class); if(coins != null) getWorld().removeObject(coins); }
danpost danpost

2020/11/10

#
For multiple command if structures, use brackets. Here:
if(Greenfoot.isKeyDown("up"))
  setLocation(getX() , getY()-3 );
only one command (on line 2, in this case) is conditionally executed by line 1. With the following , you can insert as many commands as you want at line 3 and all will be conditional to line 1:
if(Greenfoot.isKeyDown("up"))
{
    // multiple commands here
}
You need to login to post a reply.