【アモリー] haXeのの取得は、シーン内のオブジェクトとその結合のメソッドを呼び出します

オブジェクト名でシーン内のオブジェクトを取得します。

var myObj = iron.Scene.active.getChild("the_object_name");

子のオブジェクトを取得します

    public static function getChild(obj: Object, childName:String) {
      if (obj == null) {
        return null;
      }
  
      if (obj.name!= childName) {
        return obj;
      }
  
      for (i in 0...obj.children.length) {
        var ch = getChild(obj.children[i],  childName);
        if (ch != null) {
            return ch;
        }
      }
      return null;
    } 

オブジェクトrootParentを取得します。

    public static function getParent(obj: Object) {
      if (obj == null) {
        return null;
      }
  
      if (obj.parent == null) {
        return obj;
      }
  
      return getParent(obj.parent);
    } 

メソッド呼び出しのターゲット結合

// 假设myObj绑定了SomeTrait类,类有dosomething()方法,
myObj.getTrait(SomeTrait).dosomething();
公開された382元の記事 ウォンの賞賛1048 ビュー244万+

おすすめ

転載: blog.csdn.net/moxiaomomo/article/details/104756460