JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://craftyjs.com/release/0.5.4/crafty.js"></script>
JavaScript
Engine = {
degree: function(pos1, pos2) {
var dy = pos2.x - pos1.x;
var dx = pos2.y - pos1.y;
var theta = Math.atan2(dy,dx);
return theta *= 180/Math.PI;
}
}
Crafty.c('box', {
init: function() {
this.requires('2D, Canvas, Color')
.color('rgb(10,10,10)')
.attr({ w:10,h:20});
}
});
Crafty.init(480,320);
Crafty.background('gray');
var obj1 = Crafty.e('box').attr({x: 100, y:100});
Crafty.canvas._canvas.onmousedown = function(e){
var pos1 =
{
x: obj1._x,
y: obj1._y
};
var pos2 =
{
x: e.x,
y: e.y
};
obj1.rotation = 0;
obj1.rotation = Engine.degree(pos2, pos1);
}