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

2017/2/3

Moving my mouse actor

FlowerPower FlowerPower

2017/2/3

#
Hey there, I'm a little newbie at greenfoot and I was wondering how does the code should look for my mouse to move this way: it faces to the right at the beginning ,without moving. Then if i press left or right the image would change to a running image which is good.But after I press left and he runs (with the running to the left image) my mouse would go back to the facing right image .All I want is to make it face left when it's not moving if the last key pressed was left. It's like transformice. It would be helpfull if you can give me a code to make it jump too.I tried one but wasn't that good. Thank you in advance!And also sorry for grammar mistakes(if there are any).
Super_Hippo Super_Hippo

2017/2/3

#
Create a variable, save the current direction in which the mouse the moving. When it stops, use the standing right/left image depending on the variable. For the jumping, you need some initially negative (=upwards) vertical speed. In mid-air, you keep increasing this value (gravitation), so it will eventually stop moving up and move down again. Make sure you will stop moving down when the mouse hits the ground.
FlowerPower FlowerPower

2017/2/4

#
Ok thank you but how the code would look like?
Super_Hippo Super_Hippo

2017/2/4

#
private boolean direction = true; //true=right, false=left

//when moving right
direction = true;

//when moving left
direction = false;

//when not moving
if (direction && /** image is not already standing right image */) setImage( /**standing right image*/);
else if (/** image is not standing left */) setImage(/**standing left image*/);
For the jumping code, you can try to search here on the greenfoot website. There are a lot of discussions about it. Try to implement it and if it doesn't work like you want to it, show what you have tried, say what is happening and what should happen.
You need to login to post a reply.