GameObject

GameObject are the basic elements of the game, representing characters, objects, landscapes, etc. It does not have any capabilities. Each game object contains a Transform component by default, which is used to define the position and size of the game object. , The component cannot be removed.

Create GameObject

Create a game object, new GameObject(name, transfrom), the first parameter is the name of the object, and the second parameter is the properties of the object’s Transform component.

  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. })

Add child objects

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

Remove child objects

  1. gameObject.removeChild(childGameObject)

Add component

method 1:

  1. import {Img} from '@eva/plugn-renderer-img'
  2. // Method 2: Pass in the instance directly
  3. const img = new Img({
  4. // Here you can set the default parameters
  5. resource:'heart'
  6. })
  7. gameObject.addComponent(img)

Remove components

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

carry on

The Transform component that the game object carries by default is used to control the size, position, scaling, bevel, rotation and other properties of the game object.

Note:

Img, Texture, Graphics, DragonBone, SpriteAnimation, NinePatch components with graphics rendering function should not be added to the same GameObject.