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

2012/4/3

Crab tutorial - turn Greenfoot.isKeyDown() act/run

rdlatimer rdlatimer

2012/4/3

#
The code - if(Greenfoot.isKeyDown("left") { turn(3); } does not seem to work with "Act" . This works with "Run" but not with "Act" What am I doing wrong? Thanks
SPower SPower

2012/4/3

#
Maybe that's because when you hit act, the object turns a little bit, so you don't see it. And i give you this advice: if(Greenfoot.isKeyDown("left") { }
SPower SPower

2012/4/3

#
i mean: if(Greenfoot.isKeyDown("left") { turn(3); } instead of: if(Greenfoot.isKeyDown("left") { turn(3); } That's a little more readable
rdlatimer rdlatimer

2012/4/3

#
I think the run key works differently than 'act'. From the crab tutorial - With the following code: if I hold down the right arrow key and press "Act" the crab moves in a straight line. If I press "Run" and hold down the right arrow key, the crab goes in a circle. So "Act" does not seem to respond the same as "Run" for this example in the tutorial. public void moveAndTurn() { move(4); if(Greenfoot.isKeyDown("left")) { turn(-3); } if(Greenfoot.isKeyDown("right")) { turn(3); } }
davmac davmac

2012/4/3

#
That's right, the keystrokes aren't processed while the scenario isn't running, so even if you press "right" and hold it down while you click "Act", it will not register as being down. It's just the way it works.
SPower SPower

2012/4/4

#
@rdlatimer I don't think you are right. When you press act, every object will run the action act(). When you press the run button, Greenfoot simply runs the act() action for every object in the world, the whole time. So actually, the run button in Greenfoot just runs a loop where every object will run the act() method. I hope this lets you understand Greenfoot al little better. (If you're wondering where I got this information: from the Greenfoot book)
You need to login to post a reply.