Skip to content

ExampleActor

da772 edited this page Feb 27, 2020 · 2 revisions

Creating an Actor

Actors are created and handled by the current scene. Creating an actor is done by calling new Actor() inside the context of an active scene. Actors are destroyed by calling Actor.Remove().

TestScene.java

@Override
public void OnBegin() {
    Actor myActor = new Actor("myActor") // Creates new actor called my actor on this scene
    {
        @Override
        public void OnBegin() {
        // Called when created
        }

        @Override
        public void OnUpdate() {
        // Called every frame
        }

        @Override
        public void OnEnd() {
        // Called when destroyed
        }
    };
}

Destroying an Actor

TestScene.java

@Override
public void OnBegin() {
   Actor myActor = new Actor("myActor"); // Creates new actor called my actor on this scene
   Actor.Remove("myActor", this);
}

Adding/Removing Components

Actors can also have components which add additional functionality to the actors. For example, actors can have a mesh component which displays an object on the screen.

TestScene.java

@Override
public void OnBegin() {
    Actor myActor = new Actor("myActor"); // Creates new actor called my actor on this scene
    myActor.AddComponent(new Component("myComponent"));
    myActor.RemoveComponent("myComponent");
}

Previous | Next

Clone this wiki locally