TKObject Class Reference

Inherits from NSObject
Conforms to TKPropertiesOwner
Declared in TKObject.h

Overview

Represents an object on a TKObjectLayer.

Accessing the Object's Layer

  objectLayer

Reference to the object layer the object is on.

@property (weak, readonly, nullable) TKObjectLayer *objectLayer

Declared In

TKObject.h

Identifying an Object

  name

Name of the object.

@property (copy, nonnull) NSString *name

Declared In

TKObject.h

  type

The type of object assigned by the user.

@property (copy, nonnull) NSString *type

Declared In

TKObject.h

  objectType

The TKObjectType of the object, it can be either a rectangle, ellipse, closed polygon, polyline or a tile.

@property TKObjectType objectType

Declared In

TKObject.h

  objectID

The unique identifier of the object.

@property NSUInteger objectID

Declared In

TKObject.h

Object Transform

  position

The position of the object (in points).

@property CGPoint position

Discussion

Note: For polygons and polylines this equals the first point of the polygon/polyline.

Declared In

TKObject.h

  rotation

The rotation of the object (in degrees).

@property float rotation

Declared In

TKObject.h

Object Attributes

  size

The size of the object (in points).

@property CGSize size

Discussion

Note: Has no meaning for polygon and polyline objects.

Declared In

TKObject.h

  tile

The tile GID the object uses.

@property TKTileGID tile

Discussion

Note: Only valid for TKObjectTypeTile objects.

Declared In

TKObject.h

Object Shape

  path

The CGPathRef of an object that accurately represents the shape of the object. The CGPathRef is in the object’s coordinate space (relative to object’s position).

@property (readonly, nonnull) CGPathRef path

Return Value

The CGPathRef describing the object’s shape.

Discussion

Warning: You must not call CGPathRelease on the path! The CGPathRef is owned by the TKObject instance and released when the object is deallocated.

Declared In

TKObject.h

  vertices

The points making up the object’s vertices, in the object’s coordinate space. Returns nil for ellipse objects. The points for polygon objects are in the same winding as edited in Tiled. Rectangle and Tile objects are always generated in clockwise winding.

@property (readonly, nullable) CGPoint *vertices

Return Value

The list of vertexes describing this object, or nil if the object is of type ellipse.

Discussion

Warning: You must not free() this buffer. Its memory is managed by the TKObject instance.

Declared In

TKObject.h

  vertexCount

Returns the number of vertices for this object. For ellipse objects this is always 0.

@property (readonly) NSUInteger vertexCount

Declared In

TKObject.h

Rendering Attributes

  hidden

NO if the object is visible, YES if it is not visible.

@property BOOL hidden

Return Value

NO if the object is visible, YES if it is not visible.

Declared In

TKObject.h

Object Properties

  properties

The object’s TKProperties. Is nil if the object doesn’t have any properties.

@property (nonnull) TKProperties *properties

Declared In

TKObject.h

GameplayKit Methods

– obstacle

A representation of the object as GKObstacle instance for use in GKObstacleGraph. The obstacle’s vertices are offset by the object’s position, which means the obstacle is using the layer’s coordinate system.

- (nullable GKObstacle *)obstacle

Return Value

A GKPolygonObstacle or GKCircleObstacle representing the TKObject, or nil if the object is a polyline or if it’s an ellipse that’s not a perfect circle.

Discussion

Note: Polyline objects can not be converted to GKObstacle. Ellipse objects will only be converted to a GKCircleObstacle if it’s truly a circle (width and height must be identical).

Declared In

TKObject+GameplayKit.h

– createLayerCoordVectorFromVertices

Returns a memory buffer with vector_float2 types converted from the [TKObject vertices] buffer. The returned vector is in layer’s coordinate space (ie offset by object’s position).

- (nullable vector_float2 *)createLayerCoordVectorFromVertices

Return Value

A vector_float2 memory buffer with the object’s coordinates offset by object.position.

Discussion

Warning: It is your responsibility to call free() on this buffer when you don’t need it anymore.

Declared In

TKObject+GameplayKit.h