I have a strange problem, when i do the rotation passing the literal angle value(i get the previous angle printed by console and put instead the variable) it works perfectly but if i run the code passing a variable like my code below, the image is drawn "more top and more left"(sorry for my bad english)
function setImg(src,x,y,angle)
{
var TO_RADIANS = Math.PI/180;
var base_image = new Image();
base_image.src = src
base_image.onload = function () {
console.log("-->->"+parseFloat(angle))
ctx.save(); //saves the state of canvas
ctx.translate(x+(base_image.width/2), y+(base_image.height/2)); //let's translate
ctx.rotate(angle*TO_RADIANS); //increment the angle and rotate the image
ctx.drawImage(base_image, -(base_image.width/2),-(base_image.height/2)); //draw the image ;)
ctx.restore(); //restore the state of canvas
};
}
thanks!