[英]How to center a Kineticjs image from a jsonObject file?
I have images loaded from a jsonObject file with a dimension width: 26 height: 26, and I wanna center the image objects from the jsonObject file. 我有一个从jsonObject文件加载的图像,其尺寸宽度为:26高度:26,并且我想将jsonObject文件中的图像对象居中。 I tried to put width 10 and height 10, but It only crops the images from width: 26 height: 26 to width: 10 and height: 10, It dont place the images in the center.
我尝试将宽度10和高度10放在一起,但是它仅将图像从宽度:26高度:26裁剪到宽度:10和高度:10,不会将图像放置在中间。
kinImages[index] = new Kinetic.Image({
image: theImage,
x: jsonObjectsLoaded[index].x,
y: jsonObjectsLoaded[index].y,
name: jsonObjectsLoaded[index].name,
width: 10,
height: 10
});
To place the images in the center you have to change x
and y
values, not width and height. 要将图像放置在中心,必须更改
x
和y
值,而不是宽度和高度。 Set them to the stage center. 将它们设置在舞台中央。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.