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

    Fields
    Modifier and Type
    Field
    Description
    float
     
    float
     
    com.badlogic.gdx.maps.MapProperties
     

    Fields inherited from class com.badlogic.gdx.math.Rectangle

    height, tmp, tmp2, width, x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    GameObject(float x, float y, float width, float height)
    Creates an instance of a GameObject without MapProperties, functions similarily to just a normal rectangle
    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()
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    get(String key)
    Gets a property from a key
    void
    put(String key, Object value)
    Puts an Object class into the GameObject's properties
    void
    setCentreX(float x)
    Sets the new X coordinate of the centre of the object
    void
    setCentreY(float y)
    Sets the new Y coordinate of the centre of the object

    Methods 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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 layer
      scale - How much do scale the object's coordinates by, if the map is also scaled up
  • Method Details

    • put

      public void put(String key, Object value)
      Puts an Object class into the GameObject's properties
      Parameters:
      key - The key of the object
      value - The object to pass
    • get

      public Object get(String key)
      Gets a property from a key
      Parameters:
      key -
      Returns:
      The property as an object, needs to be cast
    • containsKey

      public boolean containsKey(String key)
      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 -