Package ecs
Class GameObject
java.lang.Object
ecs.GameObject
A GameObject is the root of the Entity Component system used to store all entities in Azurite games.
Each GameObject can contain any of a number of available components including spriteRenderers and lights.
By default, each GameObject contains a Transform, which holds the X and Y position, and width and height of the object in pixels.
- Author:
- Asher Haun, Gabe, Juyas
-
Field Summary
-
Constructor Summary
ConstructorDescriptionGameObject
(String name, int zIndex) GameObject
(String name, List<Component> componentList, org.joml.Vector2f position, int zIndex) Creates a new GameObject.GameObject
(String name, org.joml.Vector2f position, int zIndex) GameObject
(org.joml.Vector2f position) GameObject
(org.joml.Vector2f position, int zIndex) GameObject
(Scene scene, String name, org.joml.Vector2f position, int zIndex) Creates a new GameObject. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new component to the GameObject's list.<T> T
getComponent
(Class<T> componentClass) Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.<T> List<T>
getComponents
(Class<T> componentClass) Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.float[]
org.joml.Vector2f
long
name()
<T> void
removeComponent
(Class<T> componentClass) Takes a parameter of a class that extends component and removed it from the GameObject if it is contained in the list of components.void
setZIndex
(int z) Deprecated.void
start()
Called once on gameObject creation, also starts any components that are passed to the constructor.void
update
(float dt) Called once every frame for each GameObject, calls the update method for each component it containsint
zIndex()
-
Field Details
-
DEFAULT_GAMEOBJECT_NAME
- See Also:
-
DEFAULT_Z_INDEX
public static final int DEFAULT_Z_INDEX- See Also:
-
-
Constructor Details
-
GameObject
public GameObject(String name, List<Component> componentList, org.joml.Vector2f position, int zIndex) Creates a new GameObject.- Parameters:
name
-componentList
-position
-zIndex
-
-
GameObject
Creates a new GameObject.- Parameters:
scene
- the scene to add the GameObject to. By default, GameObjects are added to the currentScene.name
- name of the GameObjectposition
-zIndex
-
-
GameObject
- Parameters:
name
-position
-zIndex
-
-
GameObject
- Parameters:
name
-zIndex
-
-
GameObject
public GameObject(org.joml.Vector2f position, int zIndex) - Parameters:
position
-zIndex
-
-
GameObject
public GameObject(org.joml.Vector2f position) - Parameters:
position
-
-
-
Method Details
-
start
public void start()Called once on gameObject creation, also starts any components that are passed to the constructor. -
update
public void update(float dt) Called once every frame for each GameObject, calls the update method for each component it contains -
getParentScene
- Returns:
- the parent scene of this gameObject
-
getUniqueId
public long getUniqueId()- Returns:
- the universal and unique id among all objects
-
getReadOnlyPosition
public org.joml.Vector2f getReadOnlyPosition() -
getPositionData
public float[] getPositionData() -
zIndex
public int zIndex() -
setZIndex
Deprecated. -
name
-
getComponent
Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.- Parameters:
componentClass
- of component (ie. "SpriteRenderer.class")- Returns:
- Component of type passed as param is contained in GameObject
-
getComponents
Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.- Parameters:
componentClass
- of component (ie. "SpriteRenderer.class")- Returns:
- all components of type passed as param is contained in GameObject
-
removeComponent
Takes a parameter of a class that extends component and removed it from the GameObject if it is contained in the list of components.- Parameters:
componentClass
- of component (ie. "SpriteRenderer.class")
-
addComponent
Adds a new component to the GameObject's list.- Parameters:
c
- the new component- Returns:
- the gameobject itself
-
getComponents
- Returns:
- List of Components in GameObject
-