SKTile
open class SKTile : SKSpriteNode
Overview
The SKTile class is a custom SpriteKit sprite node that references its data from a tileset.
Tile data (including texture) is stored in SKTilesetData property.
Properties
| Property | Description |
|---|---|
| tileSize | tile size (in pixels) |
| tileData | tile data structure |
| layer | parent tile layer |
Instance Methods
| Method | Description |
|---|---|
| setupPhysics(shapeOf:isDynamic:) | Setup physics for the tile. |
| setupPhysics(rectSize:isDynamic:) | Setup physics for the tile. |
| setupPhysics(withSize:isDynamic:) | Setup physics for the tile. |
| runAnimation() | Play tile animation (if animated). |
| removeAnimation(restore:) | Remove animation. |
| runAnimationAsActions() | Runs a SpriteKit action to animate tile tile (if animated). |
| removeAnimationActions(restore:) | Remove the animation for the current tile. |
-
▶︎tileSizeTile size.
Declaration
Swift
open var tileSize: CGSize -
▶︎tileDataTileset tile data.
Declaration
Swift
open var tileData: SKTilesetData -
▶︎layerWeak reference to the parent layer.
Declaration
Swift
weak open var layer: SKTileLayer! -
Object is visible in camera.
Declaration
Swift
open var visibleToCamera: Bool -
Render mode for this instance.
Declaration
Swift
open var renderMode: TileRenderMode { get set } -
Returns true if the tile is part of a tile object.
Declaration
Swift
public internal(set) var isTileObject: Bool { get } -
Overview
Alignment hint used to define how to handle tile positioning within layers & objects (in the event the tile size is different than the parent).
Properties
See moreProperty Description topLeft Tile is positioned at the upper left. top Tile is positioned at top. topRight Tile is positioned at the upper right. left Tile is positioned at the left. center Tile is positioned in the center. right Tile is positioned to the right. bottomLeft Tile is positioned at the bottom left. bottom Tile is positioned at the bottom. bottomRight Tile is positioned at the bottom right. Declaration
Swift
public enum TileAlignmentHint : Intextension SKTile.TileAlignmentHint: CustomStringConvertible, CustomDebugStringConvertible -
Tile highlight color.
Declaration
Swift
open var highlightColor: SKColor -
Tile bounds color.
Declaration
Swift
open var frameColor: SKColor -
Tile highlight duration.
Declaration
Swift
open var highlightDuration: TimeInterval -
Enable tile animation.
Declaration
Swift
open var enableAnimation: Bool { get set } -
Overview:
Describes the tile’s physics shape.
Properties
See moreProperty Description none No physics shape. rectangle Rectangular object shape. ellipse Circular object shape. texture Texture-based shape. path Open path. Declaration
Swift
public enum PhysicsShapeextension SKTile.PhysicsShape: CustomStringConvertible, CustomDebugStringConvertible -
Physics body shape.
Declaration
Swift
open var physicsShape: PhysicsShape -
▶︎boundsReturns the bounding box of the shape.
Declaration
Swift
open var bounds: CGRect { get }
-
Initialize the tile object with
SKTilesetData.Declaration
Swift
required public init?(data: SKTilesetData)Parameters
dataSKTilesetDatatile data.Return Value
SKTiletile sprite. -
Default initializer.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)Parameters
aDecoderdecoder instance.
-
▶︎init()Initialize an empty tile.
Declaration
Swift
required public init() -
Initialize the tile with a tile size.
Declaration
Swift
public init(tileSize size: CGSize)Parameters
tileSizeCGSizetile size in pixels.Return Value
SKTiletile sprite. -
Initialize the tile texture.
Declaration
Swift
public init(texture: SKTexture?)Parameters
textureSKTexture?tile texture.Return Value
SKTiletile sprite. -
Draw the tile. Force the tile to update its textures.
Declaration
Swift
open func draw(debug: Bool = false)Parameters
debugBooldebug draw.
-
Set up the tile’s dynamics body.
Declaration
Swift
open func setupPhysics(shapeOf: PhysicsShape = PhysicsShape.rectangle, isDynamic: Bool = false)Parameters
shapeOfPhysicsShapetile physics shape type.isDynamicBoolphysics body is active. -
Set up the tile’s dynamics body with a rectanglular shape.
Declaration
Swift
open func setupPhysics(rectSize: CGSize, isDynamic: Bool = false)Parameters
rectSizeCGSizerectangle size.isDynamicBoolphysics body is active. -
Set up the tile’s dynamics body with a rectanglular shape.
Declaration
Swift
open func setupPhysics(withSize: CGFloat, isDynamic: Bool = false)Parameters
withSizeCGFloatrectangle size.isDynamicBoolphysics body is active. -
Set up the tile’s dynamics body with a circular shape.
Declaration
Swift
open func setupPhysics(radius: CGFloat, isDynamic: Bool = false)Parameters
radiusCGFloatcircle radius.isDynamicBoolphysics body is active. -
Remove tile physics body.
Declaration
Swift
open func removePhysics()Parameters
withSizeCGFloatdynamics body size.
-
Run tile animation.
Declaration
Swift
open func runAnimation() -
Remove tile animation.
Declaration
Swift
open func removeAnimation(restore: Bool = false)Parameters
restoreBoolrestore the initial texture.
-
Checks if the tile is animated and runs a SpriteKit action to animate it.
Declaration
Swift
open func runAnimationAsActions() -
Remove the animation for the current tile.
Declaration
Swift
open func removeAnimationActions(restore: Bool = false)Parameters
restoreBoolrestore the tile’s first texture.
-
Set the tile overlap amount.
Declaration
Swift
open func setTileOverlap(_ overlap: CGFloat)Parameters
overlapCGFloatoverlap amount.
-
Returns the points of the tile’s shape.
Declaration
Swift
open func getVertices(offset: CGPoint = CGPoint.zero) -> [CGPoint]Return Value
[CGPoint]?array of points.
-
Render the tile before each frame is rendered.
Declaration
Swift
open func update(_ deltaTime: TimeInterval)Parameters
deltaTimeTimeIntervalupdate interval.
-
▶︎opacityOpacity value of the tile.
Declaration
Swift
open var opacity: CGFloat { get set } -
▶︎visibleTile visibility.
Declaration
Swift
open var visible: Bool { get set } -
Show/hide the tile’s bounding shape.
Declaration
Swift
open var showBounds: Bool { get set } -
Tile description.
Declaration
Swift
override open var description: String { get } -
Tile debug description.
Declaration
Swift
override open var debugDescription: String { get }
-
Pauses tile animation
Declaration
Swift
@available(*, deprecated, message: "Use the default `SKNode.isPaused` to pause animation.") open var pauseAnimation: Bool { get set }
View on GitHub
SKTile Class Reference