I have successfully created a button which rotates an image either clockwise or C-Clockwise. However, this button can only be used once. i.e. if i press CW i cannot then use CCW to revert the image back.
Any ideas?
$rw = $('#rotate_right');
$rw.on('click', function(event) { event.preventDefault ? event.preventDefault() : event.returnValue = false;
darthVaderImg.offsetX(img_width / 2);
darthVaderImg.offsetY(img_height / 2);
// when we are setting {x,y} properties we are setting position of top left corner of darthVaderImg.
// but after applying offset when we are setting {x,y}
// properties we are setting position of central point of darthVaderImg.
// so we also need to move the image to see previous result
darthVaderImg.x(darthVaderImg.x() + img_width / 2);
darthVaderImg.y(darthVaderImg.y() + img_height / 2);
darthVaderImg.rotation(90);
stage.batchDraw();
export_changes();
});
$rl = $('#rotate_left');
$rl.on('click', function(event) {
event.preventDefault ? event.preventDefault() : event.returnValue = false;
//darthVaderImg.rotate(90);
darthVaderImg.offsetX(img_width / 2);
darthVaderImg.offsetY(img_height / 2);
// when we are setting {x,y} properties we are setting position of top left corner of darthVaderImg.
// but after applying offset when we are setting {x,y}
// properties we are setting position of central point of darthVaderImg.
// so we also need to move the image to see previous result
darthVaderImg.x(darthVaderImg.x() + img_width / 2);
darthVaderImg.y(darthVaderImg.y() + img_height / 2);
darthVaderImg.rotation(-90);
stage.batchDraw();
export_changes();
});`
Based on @lavrton's answer, here is a working snippet. I guess you need to pay attention to the rotation point - it was easy for me as I used a wedge. See the brief code in the button click events for illustration on what to do.
rotation
method will set the current angle of a shape. if you need to rotate more you can use this:or just: