简体   繁体   中英

How to move an image in a perfect circle around the screen?

I am rather stuck right now. I am trying to develop a game in which an image moves around the circumference of a circle, but I have no idea how to do it. I know radians, Pi and trigonometry are involved, and I know some basic maths involving them, but I cant figure out how to do it. I need the center of an image to move a certain amount on the x-axis per frame (delta-x) and a certain amount on the y-axis(delta-y.) These values will determine the movement per frame that the image must perform to give the impression that it is moving in a circular motion. I don't know how to calculate the delta-x and delta-y values, and seeing as this is a crucial component of my game, it is definitely something which needs to be taken care of. If anybody could help, I would be very grateful.

If you have the coordinates of the center and the radius of the circle it's simply

x = c.x + radius*cos(angle);
y = c.y + radius*sin(angle);

where c is the center and angle goes from 0 to 2*M_PI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM