两个Kinetic.Shape之间的比较

时间:2013-01-21 14:26:57

标签: javascript html5 canvas kineticjs

我想做两种动力学形状之间的比较:

这是我的代码:

//  -- self.group = Kinetic.Group() With 10 Shapes
//New Group
var Ngroup = new Kinetic.Group(); 
//ss New Shape
var ss = new Kinetic.Shape(); 
//Insert Current Shape Into ss
ss = getShape(t); 

// Checking If current shape exist in self.group
for(var s in self.group) {

//Check If s = ss <---

if(ss == s){

//Add The Shape to new group
alert("Found");
Ngroup.add(ss);

} else {

//Add the Old Shape to the new group
Ngroup.add(s);

}
}

此代码无效 我怎样才能比较两种形状?

1 个答案:

答案 0 :(得分:0)

对于此类复杂对象,这些不是==,您必须分别查看每个属性以进行比较。

像:

 shape1.getWidth() == shape2.getWidth() // will work as a comparison      
 shape1.getHeight() == shape2.getHeight() // will work as a comparison      
 shape1.getX() == shape2.getX() // will work as a comparison      
 shape1.getY() == shape2.getY() // will work as a comparison    
 shape1 == shape2 //will not work as the objects are not the same object. Even the z-index is different.  

所有属性都在文档中列出,并带有相应的功能:http://kineticjs.com/docs/symbols/Kinetic.Node.php