Package com.skloch.game
Class GameObject
java.lang.Object
com.badlogic.gdx.math.Rectangle
com.skloch.game.GameObject
- All Implemented Interfaces:
com.badlogic.gdx.math.Shape2D
,Serializable
public class GameObject
extends com.badlogic.gdx.math.Rectangle
An object that stores a position and dimensions, but can also store extra properties when loaded from a tilemap.
Player can interact and trigger events with these objects.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfloat
float
com.badlogic.gdx.maps.MapProperties
Fields inherited from class com.badlogic.gdx.math.Rectangle
height, tmp, tmp2, width, x, y
-
Constructor Summary
ConstructorsConstructorDescriptionGameObject
(float x, float y, float width, float height) Creates an instance of a GameObject without MapProperties, functions similarily to just a normal rectangleGameObject
(com.badlogic.gdx.maps.MapProperties objectProperties, float scale) Creates a GameObject using the MapProperties stored in a object when exported with the Tiled map editor Sets x, y, width and height, as well as loading all other properties which can be fetched with get() -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String key) Gets a property from a keyvoid
Puts an Object class into the GameObject's propertiesvoid
setCentreX
(float x) Sets the new X coordinate of the centre of the objectvoid
setCentreY
(float y) Sets the new Y coordinate of the centre of the objectMethods inherited from class com.badlogic.gdx.math.Rectangle
area, contains, contains, contains, contains, equals, fitInside, fitOutside, fromString, getAspectRatio, getCenter, getHeight, getPosition, getSize, getWidth, getX, getY, hashCode, merge, merge, merge, merge, overlaps, perimeter, set, set, setCenter, setCenter, setHeight, setPosition, setPosition, setSize, setSize, setWidth, setX, setY, toString
-
Field Details
-
properties
public com.badlogic.gdx.maps.MapProperties properties -
centreX
public float centreX -
centreY
public float centreY
-
-
Constructor Details
-
GameObject
public GameObject(float x, float y, float width, float height) Creates an instance of a GameObject without MapProperties, functions similarily to just a normal rectangle- Parameters:
x
-y
-width
-height
-
-
GameObject
public GameObject(com.badlogic.gdx.maps.MapProperties objectProperties, float scale) Creates a GameObject using the MapProperties stored in a object when exported with the Tiled map editor Sets x, y, width and height, as well as loading all other properties which can be fetched with get()- Parameters:
objectProperties
- An instance of MapProperties loaded from an object layerscale
- How much do scale the object's coordinates by, if the map is also scaled up
-
-
Method Details
-
put
Puts an Object class into the GameObject's properties- Parameters:
key
- The key of the objectvalue
- The object to pass
-
get
Gets a property from a key- Parameters:
key
-- Returns:
- The property as an object, needs to be cast
-
containsKey
- Parameters:
key
- A key to be checked in the object's properties- Returns:
- True if the object has a property with this key
-
setCentreY
public void setCentreY(float y) Sets the new Y coordinate of the centre of the object- Parameters:
y
-
-
setCentreX
public void setCentreX(float x) Sets the new X coordinate of the centre of the object- Parameters:
x
-
-