1

2 つのキネティック シェイプの比較を行いたい:

これは私のコードです:

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

}
}

このコードは機能していません
。どうすれば 2 つの形状を比較できますか?

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 に答える