我已经成功创建了一个按钮,它可以顺时针或顺时针旋转图像。但是,此按钮只能使用一次。即如果我按CW,我不能使用CCW将图像还原。Knovajs/HTML5画布 - 旋转起源
任何想法?
$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();
});`
精湛。这样可行。任何想法改变图像(不是方形)并更新它的旋转偏移到中心?即在风景中我已经制定了中心。其中,当按旋转它第一次工作。但再次按旋转它会出错。 – deanhodges