Here is a game I am working on has a gun that rotates to track the cursor on jsfiddle.
http://jsfiddle.net/otherDewi/zqeLW/
I am trying to get it to work in IE9. I have included jqueryRotate but it does not seem to have made a difference. I was expecting to set the rotation in degrees but it only works in radians in Firefox and Chrome. Unsure if jQueryRotate is linked correctly.
Lines 47-60 in main.js set the rotation:
$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);
});
which is used by the draw function in lines 94-111:
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
I discovered today that my code throws a
SYNTAX_ERR code 12
An invalid or illegal string has been specified; for example setting the selectorText property of a CSSStyleRule with an invalid CSS value..
I have checked the script for invalid file names, unsure if the event handler is causing problems.