2012-10-13 18 views
4

假設我有一個類似於下面的代碼。從craftyjs中的對象獲取組件類型

Crafty.c("SomeType",{//do something... }); 
var obj=Crafty.e("SomeType"); 

誰能告訴我是否有函數來檢查對象的類型嗎?

例:

Crafty.isComponent(obj,"SomeType")==true 

Crafty.getComponents(obj)=="SomeType" 

回答

4

阿發現從Crafty.js文件,有一個。先後()函數來檢查一個組件。 :)

/**@ 
    * #.has 
    * @comp Crafty Core 
    * @sign public Boolean .has(String component) 
    * Returns `true` or `false` depending on if the 
    * entity has the given component. 
    * 
    * For better performance, simply use the `.__c` object 
    * which will be `true` if the entity has the component or 
    * will not exist (or be `false`). 
    */ 
相關問題