如果我在舞台上有图像:
var stage = new Kinetic.Stage({
container : "cantainer",
width : 400,
height : 400
});
var layer = new Kinetic.Layer();
stage.add(layer);
var img = new Image();
img.src ="https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg"
img.onload = function(){
pic = new Kinetic.Image({ x: 0, y: 0, width: 251, height: 231,image: img});
layer.add(pic);
layer.draw();
}
如何更改“pic”之后的x / y值......?
THX!
答案 0 :(得分:1)
赋予Kinetic Image一个id,以便更容易追溯:
pic = new Kinetic.Image({
x: 0,
y: 0,
width: 251,
height: 231,
image: img,
id: 'img1'
});
将图像添加到图层后,您可以使用:
var x = [your x];
var y = [your y];
layer.get('#img1')[0].setPosition(x,y);
layer.draw();