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

2012/2/2

rolling 2d Ball

lostinjava lostinjava

2012/2/2

#
i'm looking for a way to make a ball rolling from one side to another . i'm getting somewhat frustrated because with the turn method de ball is turning around the axis but when i ad the move method te ball is turning big circles and not to te side of the world . can someone give a noob like me a tip ? thx
Morran Morran

2012/2/2

#
The "move()" method moves the Actor in the direction that Actor is facing. What you want is something that moves independently of which way it faces. Use "setLocation(int newX, int newY)" instead. So, if you want the ball to move to the left, just use "setLocation(getX() - speed, getY());" If you want it to move to the right, use "setLocation(getX() + speed, getY());" To move it up, "setLocation(getX(), getY() - speed);", and down: "setLocation(getX(), getY() + speed);". Where "speed" is an integer. Play around with its value, but I'd say speed = 10 is a good place to start.
lostinjava lostinjava

2012/2/3

#
thanx a lot Morran !! this really helped me .
You need to login to post a reply.