,

      游戏对象 GameObject

      游戏对象是游戏的基本元素,代表人物、物体、风景等,它本身没有任何能力,每一个游戏对象都默认包含一个 Transform 组件,这个组件用来定义游戏对象的位置、尺寸等信息,该组件无法被移除。

      创建游戏对象

      创建游戏对象, new GameObject(name, transfrom) ,第一个参数为对象的名称,第二个参数为对象的 Transform 组件的属性。

      1. import { GameObject } from ‘@eva/eva.js’
      2. const gameObject = new GameObject(‘name’, {
      3. size: { width: 100, height: 100 },
      4. position: { x: 50, y: 50 }
      5. })

      添加子对象

      1. const childGameObject = new GameObject(‘b’, {})
      2. gameObject.addChild(childGameObject)

      移除子对象

      1. gameObject.removeChild(childGameObject)

      添加组件

      方法 1:

      1. import { Img } from ‘@eva/plugn-renderer-img’
      2. // 方法2:直接传入实例
      3. const img = new Img({
      4. // 这里可以设置默认参数
      5. resource: ‘heart’
      6. })
      7. gameObject.addComponent(img)

      移除组件

      1. import { Img } from ‘@eva/plugn-renderer-img’
      2. gameObject.removeComponent(Img)

      继续

      游戏对象默认携带的 Transform 组件是用来控制游戏对象的尺寸、位置、缩放、斜切、旋转等属性。

      注意:

      Img、Texture、Graphics、DragonBone、SpriteAnimation、NinePatch 有图形渲染功能的组件不要添加到同一个 GameObject 内。

      ,