1

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

这是我的代码:

//  -- 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);

}
}

此代码不起作用
我如何比较两个形状?

4

1 回答 1

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

于 2013-01-21T15:36:05.810 回答