2.4. Working with Objects Document
Previous: Working with Layers - Next: Working with Tile Animations — Return to Index
The proeprties and methods for object types are largely identical, except for certain special cases where a property may not be valid for a given object type. This is noted in the class reference.
position is in the layer’s (map’s) coordinate system. Its
rotation property is in degrees.
size determines the width and height of rectangle and tile objects, as well as the shape of ellipse objects. Ellipse objects whose width and height are equal are simply circles.
vertices of an object are in the object’s local coordinate space, ie relative to the object’s
Identifying Objects and their Type
To determine an object’s type you have several options:
- The TKObjectType (rectangle, ellipse, polygon, polyline, tile) assigned to the
nameproperty, a string editable in an object’s properties pane in Tiled (labelled “Name”).
typeproperty, a string editable in an object’s properties pane in Tiled (labelled “Type”).
objectIDwhich is a consecutive, unique number applied to every object and shown in the object’s properties pane in Tiled as “ID”.
type properties allow you to customize objects, besides using custom properties. Specifically
type is made for differentiating objects, ie indicating a concrete node class or unit type.
Object Type Differences
objectType property will tell you what to make of certain properties.
positionproperty is set to the first point of a polygon or polyline object.
sizeproperty has no meaning (is CGSizeZero) for polygon and polyline objects.
tileproperty is only valid (non-zero) for tile objects.
verticesproperty and the
createLayerCoordVectorFromVerticeswill return nil for ellipse objects. Unsurprisingly,
vertexCountwill be 0 for ellipse objects.
obstaclemethod will return nil for polyline objects, as well as ellipse objects that aren’t circles (same width and height).
Using the Object’s Shape
There are several ways to use the object’s shape.
pathproperty returns a CGPathRef instance describing the object’s shape.
verticesproperty returns the object’s vertices as a
CGPoint*buffer. The number of vertices is returned by the
createLayerCoordVectorFromVerticesmethod is the same as
verticesexcept that it’s a
vector_float2*buffer for use with GameplayKit.
obstaclemethod will return a GKPolygonObstacle or GKCircleObstacle for use with GameplayKit.