-
Notifications
You must be signed in to change notification settings - Fork 0
Add and Remove GameObject
Radomiej edited this page Apr 4, 2017
·
7 revisions
To add new GameObject you must invoke method instantiateGameObject() in Scene or JComponent object with start position.
Example for Scene builder:
JGameObject gameControllerObject = scene.instantiateGameObject(new Vector2(0, 0));
Example for JComponent:
public class MapComponent extends JComponent{
private ArrayList<JGameObject> gameObjects = new ArrayList<JGameObject>();
int minZoom = 4;
int maxZoom = 17;
@Override
public void start() {
System.out.println("start Map");
for(int x = minZoom; x < maxZoom; x++){
JGameObject layer = instantiateGameObject(getTransform().getPosition());
layer.addComponent(layer, new LayerComponent(x));
layer.getTransform().setParent(getGameObject());
}
}
}To remove GameObject you must use destroyGameObject method from current Scene object. Example remove this gameObject after 2s(60 tick update per secound):
public class MyComponent extends DefaultComponent {
public int count = 120;
@Override
public void update() {
count--;
if (count == 0) {
destroyGameObject(getGameObject());
}
}
}eqivalent:
public class MyComponent extends DefaultComponent {
@Override
public void start() {
destroyGameObject(getGameObject(), 2);
}
}