[英]Rotating layer or Image with offset in kineticjs
我有一个dynamicjs应用程序,其中包括以下内容
我的舞台已固定大小800x600
//global variables
var stageWidth = 800;
var stageHeight = 600;
stage = new Kinetic.Stage({
width: stageWidth,
height:stageHeight,
container: 'container',
x: 0,
y: 0
});
我的backgroundLayer大小也固定,处于舞台顶部
backgroundLayer = new Kinetic.Layer({
width:stageWidth,
height: stageHeight,
x: 0,
y: 0,
draggable: false,
offset: [stageWidth / 2, stageHeight / 2]
});
我的Kineticjs图像的大小取决于图像的大小。 因此,如果图像是垂直的,则其高度为600,并根据舞台尺寸的比例调整宽度。 当图像为纵向时,其操作方式相同
function initializeImage(id){
var domImage = $("#"+id);
var imageSrc = domImage.prop('src');
imageObj = new Image();
imageObj.src = imageSrc;
if (imageWidth > imageHeight){
imageWidth = stageWidth;
imageHeight = imageWidth / ratio;
imageY = (stageHeight - imageHeight) / 2;
}else{
imageHeight = stageHeight;
imageWidth = stageHeight / ratio;
imageX = (stageWidth - imageWidth) / 2;
}
domImage.remove();
}
然后我按如下方式初始化the kinetijs图像对象
imageObj.onload = function (){
backgroundImage = new Kinetic.Image({
image:imageObj,
width:imageWidth,
height:imageHeight,
x:imageX,
y:imageY
});
然后按以下顺序添加它们
backgroundLayer.add(backgroundImage);
stage.add(backgroundLayer);
我的问题是,当我尝试旋转Image或使用offset旋转的Layer无法工作时。 我遇到以下问题
我的代码有问题吗?我是否理解不正确?
看起来您需要更改API(必须传递对象,而不是数组):
offset: {
x : stageWidth / 2,
y : stageHeight / 2
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.