0

这是我正在开发的一款游戏,它有一把可以旋转的枪来跟踪 jsfiddle 上的光标。

http://jsfiddle.net/otherDewi/zqeLW/

我试图让它在 IE9 中工作。我已经包含了 jqueryRotate,但它似乎没有什么不同。我期待以度为单位设置旋转,但它仅适用于 Firefox 和 Chrome 中的弧度。不确定 jQueryRotate 是否正确链接。

main.js中的第 47-60 行设置旋转:

$canvas.mousemove(function (e) {
    xHair = e.pageX;
    yHair = e.pageY;

    //gun position
    xGPos = xHair / 4 + 280;
    yGPos = yHair / 4 + 200;
    difx = xHair - (235 + xGPos);
    dify = yHair - (230 + yGPos);
    radians = Math.atan2(dify, difx);
    rotation = radians + 2.36; //rotation in radians
    //rotation = (((radians*180)/Math.PI)+135); rotation in degrees
    console.log(rotation);
});

第 94-111 行中的 draw 函数使用它:

function draw(ctx, xGPos, yGPos, difx, dify, rotation) {
    // gun/Linked File
    ctx.save();
    ctx.translate(235 + xGPos, 230 + yGPos);
    //console.log(rotation);
    ctx.rotate(rotation);
    ctx.translate(-235 - xGPos, -230 - yGPos);
    ctx.drawImage(img2, xGPos, yGPos);
    ctx.restore();
};

https://github.com/KiwiTaff/duck-hunt-git2/blob/master/js/main.js

我今天发现我的代码抛出了一个

SYNTAX_ERR code 12

指定了无效或非法的字符串;例如,使用无效的 CSS 值设置 CSSStyleRule 的 selectorText 属性。

我检查了脚本是否有无效的文件名,不确定事件处理程序是否导致问题。

4

0 回答 0