开发者

How to rotate 2 images independently on html canvas

开发者 https://www.devze.com 2023-04-04 15:50 出处:网络
I want to show a set of gears using HTML canvas. I\'ve got the following http://jsfiddle.net/jeepstone/RpmuE/ but the little cog rotates 开发者_Go百科around the big cog rather than staying fixed and j

I want to show a set of gears using HTML canvas. I've got the following http://jsfiddle.net/jeepstone/RpmuE/ but the little cog rotates 开发者_Go百科around the big cog rather than staying fixed and just rotating. Once I have it fixed I can work out the relative speeds of the cogs but I can't work out why it moves around the main cog.

Any ideas?


Demo

Hah cool idea, the main thing I think causing the issue was a missing restore. A thing to remember is you want to do your translates before the rotations. Otherwise you will translate the canvas, and then rotate the whole canvas thus rotating everything on the context.


Ah ok. That makes sense. Bring on the gearbox!

0

精彩评论

暂无评论...
验证码 换一张
取 消