【发布时间】:2015-07-06 23:58:25
【问题描述】:
我在画布内绘制了一个图像,它被裁剪成 4 个不同的部分。例如,我想旋转第二个裁剪区域围绕其中心的最顶部。
现在,如果我改变translate的值,旋转和以前一样,唯一的区别是posX,posY改变了。
绘图功能:
//Function that is called on each 'tick' event, 60fps
draw: function(){
if(this.rotation != 0){
_self.elements.context.save();
// what values to put here so that '2' would rotate correctly ???
_self.elements.context.translate(0,0);
_self.elements.context.rotate(this.rotation);
_self.elements.context.drawImage(
_self.elements.image,this.sx, this.sy, this.sw, this.sh, this.dx, this.dy, this.sw, this.dh
);
_self.elements.context.restore();
}else{
_self.elements.context.drawImage(
_self.elements.image, this.sx, this.sy, this.sw, this.sh, this.dx, this.dy, this.sw, this.dh
);
}
}
使用 TweenMax 进行旋转
//Rotate the '2' cropped image part
TweenMax.to(_self.CanvasImages.collection[1], 2, {rotation:0.5});
我还在jsFiddle 中提供了完整的代码,这应该可以更好地理解我在说什么。
【问题讨论】:
标签: javascript canvas gsap