【问题标题】:Comparison between two Kinetic.Shape两个 Kinetic.Shape 之间的比较
【发布时间】:2013-01-04 15:08:30
【问题描述】:

我想在两个动力学形状之间进行比较:

这是我的代码:

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

}
}

此代码无效
如何比较两个形状?

【问题讨论】:

  • 我认为你必须弄清楚两个“Shape”对象的“==”是什么意思。如果它们的大小相同,红色三角形 == 到蓝色三角形吗?如果他们处于不同的位置怎么办?
  • 如何获取形状位置?
  • 我认为父类(“节点”)上有一个 API。我只是browsing the documentation;我不是图书馆方面的专家。
  • 嗯,API 文档有点少。有一个“getPosition()”函数,但没有描述返回值。

标签: javascript html canvas kineticjs


【解决方案1】:

对于如此复杂的对象,这些没有==,您必须单独查看每个属性以进行比较。

喜欢:

 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

【讨论】:

    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 2012-05-30
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多