我试图让这 2 个 png 图像在我的画布上简单地旋转。图像比画布大,因为我只想在轮子旋转到画布时显示轮子的某些部分。我在画布上完美地得到了 png,它们是圆形的,与底部对齐并居中,因此它只显示轮子的那个部分。我在我的代码中使用 createjs 和 easl 和 tween。出于某种原因,当我旋转图像时,它会从某个随机注册点进行旋转。有没有办法让这个图像围绕它自己的中心旋转,它不在画布区域?
var CANVAS;
var STAGE;
var CTX;
var imageCount = 0;
var img1Obj = new Image();
var img2Obj = new Image();
var img3Obj = new Image();
var img1;
var img2;
var img3;
var box;
function init(){
CANVAS = document.getElementById("spinWheel");
STAGE = new createjs.Stage(CANVAS);
CTX = CANVAS.getContext('2d');
img1Obj.src = "img/iphone_wheel_outer.png";
img2Obj.src = "img/iphone_wheel_middle.png";
img3Obj.src = "img/iphone_wheel_inner.png";
img1Obj.name = "img1";
img2Obj.name = "img2";
img3Obj.name = "img3";
img1Obj.onload = loadImages;
img2Obj.onload = loadImages;
img3Obj.onload = loadImages;
createjs.Ticker.setFPS(30);
createjs.Ticker.addListener(STAGE);
}
function loadImages(e)
{
if(e.target.name == 'img1'){img1 = new createjs.Bitmap(img1Obj); }
if(e.target.name == 'img2'){img2 = new createjs.Bitmap(img2Obj); }
if(e.target.name == 'img3'){img3 = new createjs.Bitmap(img3Obj); }
imageCount++;
/* Display graphics until all of them are loaded */
if(imageCount == 3)
{
buildInterface();
}
}
function buildInterface(){
img1.x = -370;
img2.x = -370;
img3.x = -370;
img1.y = 235;
img2.y = 235;
img3.y = 235;
createjs.Tween.get(img1,{loop:true})
.to({rotation : 360}, 2000);
STAGE.addChild(img1, img2, img3, box);
}
$(document).ready(function() {
init();
});