I've been trying to get my player entity to rotate to the mouse however I cannot get the MouseMove event to trigger.
Crafty.e("2D, Mouse, Canvas, Color"
.attr({ w:1000, h:1000, x:0, y:0 })
.bind('MouseMove', function(e)
{
console.log("Mouse Pos:"+ e.x +","+e.y);
//get hero
var pos1 = {
x: e.x,
y: e.y
}
var pos2 = {
x: player.x,
y: player.y
}
player.rotation = 0;
player.rotation = -Engine.degree(pos1, pos2);
})
When I replace MouseMove with click or mousedown or any other mouse event, it rotates to the mouse when that event occurs. However it never calls the mousemove function. What am I doing wrong?
Have a look at CraftyMouseFace, a Crafty component made by the community:
The first feature sounds like what you need.
Let's put the
MouseMovedevent and its event data to test in the following snippet.Move the mouse pointer around and notice how the green rectangle rotates to face the pointer.