简体   繁体   English

帆布像大轮子一样旋转矩形

[英]Canvas rotate rectangle like big wheel

So I have a level and want the x,y of a rect to move around like a big wheel. 因此,我有一个水平,希望矩形的x,y像大轮子一样四处移动。 I am going to use it as a platform to reach the end point. 我将使用它作为到达终点的平台。 So every frame it moves 1 or 2 pixels. 因此,每一帧它移动1或2像素。 Just wondering how to go about this? 只是想知道如何去做?

I can do a diamond shape easily enough by for 50 loops the x would be ++; 我可以很容易地通过50个循环来制作菱形,x就是++; and the y would be ++; y为++; then after 50 the x would be --; 然后在50之后x将是-; and the y would be ++; y为++; and so on. 等等。

How is a circle done? 如何做一个圆?

Not quite sure what you are trying to do, but if I understand the question right, you should store the current angle of the rectangle, theta , and then update x and y as r*sin(theta)+offset_x and r*cos(theta)+offset_y where the offsets are the position of the centre of rotation. 不太确定您要做什么,但是如果我理解正确的问题,则应存储矩形的当前角度theta ,然后将xy更新为r*sin(theta)+offset_xr*cos(theta)+offset_y ,其中偏移是旋转中心的位置。 Then each frame increase theta by some small amount. 然后,每帧将theta增加一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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