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

2020/6/4

How do i make an object move up and down but without rotation?

lilshopa lilshopa

2020/6/4

#
So im trying to create a game for a project in my university and my main character is facing the right and can move up and down but i dont know how to do it without him rotating.
danpost danpost

2020/6/4

#
lilshopa wrote...
So im trying to create a game for a project in my university and my main character is facing the right and can move up and down but i dont know how to do it without him rotating.
With a direction indicating field, whose value is limited to plus or minus one:
private int dir = 1;
you can use:
setLocation(getX(), getY()+dir); // dir can be multiplied by speed
to move. And to turn around, use:
dir = -dir;
lilshopa lilshopa

2020/6/4

#
thank you so much!!!!!!!!!!!
You need to login to post a reply.