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

2017/2/24

ask

ajiereus ajiereus

2017/2/24

#
how if i want to stop moving object and start moving again the object ?
aldrisang aldrisang

2017/2/24

#
well you'd move() in the act() function, so just make some global variable that'd store whether you should be moving or not, update it wherever appropriate, and check to see if it's true or false (1 or 0) before your move() command. basically, in act() function: if (shouldMove) { move(4); } and somewhere at the top where your class opens, define your variable: private shouldMove; either set it to something right there, or initialize it in the class constructor (which you would have to create); public MyClassName() { shouldMove = 0; } at whatever point it should be stopping, just do this: shouldMove = 1; i'm going to bed or i'd be more specific... good luck!
Super_Hippo Super_Hippo

2017/2/24

#
private boolean moving = true;

//in act
if (moving) move(5);


public void toggleMoving()
{
    moving = !moving;
}
Then you only need a reference to object and call the 'toggleMoving' method on it.
aldrisang aldrisang

2017/2/24

#
oops yeah i forgot to say boolean or int for mine, and i got my 0s and 1s mixed up. man i'm tired. i'm sure they'll figure it out :) ciao for now...
You need to login to post a reply.