Skip to content

Add and Remove GameObject

Radomiej edited this page Oct 6, 2016 · 7 revisions

Add new GameObject

To add new GameObject you must have Prefab or other exist GameObject to clone him. And you must set new position instantiate object. Example:

public class MapComponent extends DefaultComponent {
	private ArrayList<JGameObjectImpl> gameObject = new ArrayList<JGameObjectImpl>();
	
	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());			
		}		
	}	
}

Remove GameObject

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());
		}
	}	
}

Clone this wiki locally