Class MapObject
java.lang.Object
org.openpatch.scratch.tiled.MapObject
Represents a map object with various properties such as dimensions, position,
visibility, and
type. It also provides methods to retrieve property values in different
formats and to get a
Shape representation of the map object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionAn object representing an ellipse shape.doubleThe height of the map object.intThe unique identifier of the map object.The name of the map object.An object representing a point.A list of properties associated with the map object.doubleThe rotation angle of the map object.The type of the map object.booleanThe visibility status of the map object.doubleThe width of the map object.doubleThe x-coordinate of the map object.doubleThe y-coordinate of the map object. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetProperty(String name) Retrieves the value of a property with the specified name from the properties list.booleangetPropertyBoolean(String name) Retrieves the value of the specified property as a boolean.floatgetPropertyFloat(String name) Retrieves the value of a specified property as a float.intgetPropertyInt(String name) Retrieves the value of a property with the specified name and converts it to an integer.getShape()Returns a Shape object representing the current map object.voidsetClassName(String className) Tiled 1.9 renamed an object's type to class; both end up intype(an explicit type wins).
-
Field Details
-
height
public double heightThe height of the map object. -
id
public int idThe unique identifier of the map object. -
name
The name of the map object. -
rotation
public double rotationThe rotation angle of the map object. -
visible
public boolean visibleThe visibility status of the map object. -
width
public double widthThe width of the map object. -
type
The type of the map object. -
x
public double xThe x-coordinate of the map object. -
y
public double yThe y-coordinate of the map object. -
properties
-
ellipse
An object representing an ellipse shape. -
point
An object representing a point.
-
-
Constructor Details
-
MapObject
public MapObject()
-
-
Method Details
-
setClassName
-
getPropertyInt
Retrieves the value of a property with the specified name and converts it to an integer.- Parameters:
name- the name of the property to retrieve- Returns:
- the integer value of the property
- Throws:
NumberFormatException- if the property value cannot be parsed as an integer
-
getProperty
-
getPropertyFloat
Retrieves the value of a specified property as a float.- Parameters:
name- the name of the property to retrieve- Returns:
- the float value of the specified property
- Throws:
NumberFormatException- if the property value cannot be parsed as a float
-
getPropertyBoolean
Retrieves the value of the specified property as a boolean.- Parameters:
name- the name of the property to retrieve- Returns:
- the boolean value of the property, or false if the property is not found or cannot be parsed as a boolean
-
getShape
Returns a Shape object representing the current map object. The type of Shape returned depends on the properties of the map object: - If the object is a point, a 1x1 rectangle is returned. - If the object is an ellipse, an Ellipse2D object with the specified width and height is returned. - If the object is a polygon, a Polygon object with the specified points is returned. - If none of the above conditions are met, a rectangle with the specified width and height is returned.- Returns:
- a Shape object representing the current map object.
-