admin管理员组文章数量:1387404
I know it's something wrong with my transformations in drawGuy. Can anyone help me figure out how to rotate just the image? Currently it rotates fine, but I something with the transforms is distorting it, so that it doesn't follow the mouse correctly.
http://gist.github./232194
I know it's something wrong with my transformations in drawGuy. Can anyone help me figure out how to rotate just the image? Currently it rotates fine, but I something with the transforms is distorting it, so that it doesn't follow the mouse correctly.
Share Improve this question asked Nov 11, 2009 at 18:59 Timothy McDowellTimothy McDowell 2372 silver badges10 bronze badges1 Answer
Reset to default 7Instead of translating forward and then translating backward again, simply push your current state onto the stack before you traslate/rotate, and when you're done - pop your state back off the stack. This is how most graphical applications make use of translations/rotations.
Also, you're translating by x, y
, then additionally calling ctx.drawImage(guy, x, y)
. This is going to, in effect, double the offset. I'd either get rid of the translate call, or change the position arguments for the drawImage call to 0, 0
.
function drawGuy() {
ctx.save();
ctx.translate(x,y);
ctx.rotate(angle * Math.PI / 180);
ctx.drawImage(guy, 0, 0);
ctx.restore();
}
Check out the spec about context.save()
and context.restore()
(the way canvas does state push/pop), here.
本文标签:
版权声明:本文标题:I just want to rotate and move the image!! (Javascript, <canvas>, html 5) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744552997a2612298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论