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

2015/3/6

how tu make a picture spin around in circle

Dudeson Dudeson

2015/3/6

#
Hello , so I've been wondering how to spin object around without turning it degrees , I mean picture has to stay as it it's but spin around. Let's say my picture spin around invisible circle 50 px x,y. I've been trying do it my self but I'am bigginer so , I tryed to write every pixel to position ball every move but for me it looks stupid and code would be so big and comlicated. My question is maybe there is any easy technique or function I could use to do that?
danpost danpost

2015/3/6

#
By "invisible circle", I take it you want your actor to make circles around a specific point where 50 px is the radius of the circle and x, y is the point to circle around (or orbit). You will need three fields for that: two for the coordinates of the point to circle around and one to track the current orbital rotation (since the rotation of the actor cannot be used if it is to remain at zero). Each act (or each time it changes location around its circle), reset its location to the center, add the change in its rotation to the rotation field, set the rotation of the actor to that rotation value, move 50 pixels forward, and finally reset the rotation of the actor back to zero. Only the end result will be visible to the user (none of the actions done during the execution of the act method will be apparent to the user).
Dudeson Dudeson

2015/3/6

#
Could you show me an example ?
danpost danpost

2015/3/6

#
1
2
3
4
5
6
7
8
9
10
11
12
int centerX = 100;
int centerY = 100;
int radius = 50;
int rotation = 0;
int turnSpeed = 1;
// in act
setLocation(centerX, centerY); // move to center
setRotation(rotation); // rotate actor to old rotation
turn(turnSpeed); // add change in rotation of actor
rotation = getRotation(); // save new rotation value
move(radius); // move to edge of circle
setRotation(0); // un-rotate actor
Dudeson Dudeson

2015/3/6

#
Thanks , I'll try it .
Dudeson Dudeson

2015/3/6

#
Thanks ! Works great! That's what I needed :)
Srax Srax

2015/3/25

#
in the act method, put "turn(1);" then it will turn around in a circle...
Super_Hippo Super_Hippo

2015/3/25

#
Srax wrote...
in the act method, put "turn(1);" then it will turn around in a circle...
Re-read the first post. That's exactly not what was wanted.
You need to login to post a reply.