Javascript旋转精灵?

时间:2014-06-29 13:45:26

标签: javascript html5 rotation sprite angle

所以我和朋友一起做这个游戏。我们在让精灵旋转时遇到一些麻烦。角度始终为-2.356194490192345。谁能告诉我下面的代码有什么问题?

  

var angle = Math.atan2(mouse.y-MC.drawY,mouse.x-MC.drawX);

//Rotating the sprite to face mouse
//Get mouse position
document.addEventListener('mousemove', function(e){ 
    mouse.x = e.clientX || e.pageX; 
    mouse.y = e.clientY || e.pageY;
}, false);

> function DrawMainChar(){
>     ctx.clearRect( 0 , 0 , 800 , 600 );
>     ctx.save();
>     ctx.translate(MC.drawX+8, MC.drawY+8);
>     ctx.rotate(angle);
>     ctx.translate(-MC.drawX+8, -MC.drawY+8);
>     ctx.drawImage(imgSprite, MC.srcX, MC.srcY, MC.width, MC.height, MC.drawX, MC.drawY, MC.width, MC.height);
>     ctx.restore();    //RoundStarter(); 
   }

0 个答案:

没有答案