我正在使用最新的kineticjs。(v.3.10) 问题来了
我使用单个函数将单击时位于 Canvas 外部的图像发送到 Canvas 。 我正在使图像可拖动并且所有.. 我还添加了双击删除图像功能。 当我双击任何图像时.. 最后添加的图像被删除,之后如果我尝试单击其他图像.. 我收到此错误:TypeError:this.children[child.index]未定义
这里有一些代码:
使用此函数使用ajax从另一个文件获取路径
function loadajax(imgpath,imgid){
sources = {
yoda1 : imgpath,
};
loadImages(sources,initStage1);
};
来源功能:----
function loadImages(sources, callback){
var images = {};
var loadedImages = 0;
var numImages = 0;
for (var src in sources) {
numImages++;
}
for (var src in sources) {
images[src] = new Image();
images[src].onload = function(){
if (++loadedImages >= numImages) {
callback(images);
}
};
images[src].src = sources[src];
}
}
这是我用来删除/拖放/等的功能。
function initStage1(images){
yodaGroup1 = new Kinetic.Group({
x: 100,
y: 110,
draggable: true,
});
layery = new Kinetic.Layer();
layery.add(yodaGroup1);
stage.add(layery);
var yoda1 = new Kinetic.Image({
image: images.yoda1,
x: 0,
y: 0,
width: 100,
height: 120,
name:"image",
detectionType:"Pixel"
});
yodaGroup1.add(yoda1);
yodaGroup1.on("dragstart", function() {
yodaGroup1.moveToTop();
layery.draw();
});
yodaGroup1.on("dblclick dbltap", function() {
layery.remove(yodaGroup1);
layery.draw();
});
yodaGroup1.on("dragend", function() {
layery.draw();
yoda1.saveImageData();
});
addAnchor(yodaGroup1,0, 0, "topLeft");
addAnchor(yodaGroup1, 100, 0, "topRight");
addAnchor(yodaGroup1, 100, 120, "bottomRight");
addAnchor(yodaGroup1, 0, 120, "bottomLeft");
stage.draw();
yoda1.saveImageData();
}
NOW根据这个函数 我应该能够将图像添加到 Canvas 上(工作正常) 当我拖动它时应该能够将一个图像移动到另一个图像上(即moveToTop函数)_不工作 应该能够通过双击删除图像(仅适用于最新添加的图像)
请帮忙
谢谢
最佳答案
layery.remove(yodaGroup1);
指的是这个函数:
- remove() 从舞台上移除图层
http://www.kineticjs.com/docs/symbols/Kinetic.Layer.php#remove
没有功能可以仅删除该层中包含的一个节点:/
关于javascript - 图层.删除(图像);无法在 Kinetic.js 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11954841/