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. |
-
▶︎tileSize
Tile size.
Declaration
Swift
open var tileSize: CGSize
-
▶︎tileData
Tileset tile data.
Declaration
Swift
open var tileData: SKTilesetData
-
▶︎layer
Weak 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
Property 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 : Int
extension 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
Property Description none No physics shape. rectangle Rectangular object shape. ellipse Circular object shape. texture Texture-based shape. path Open path. Declaration
Swift
public enum PhysicsShape
extension SKTile.PhysicsShape: CustomStringConvertible, CustomDebugStringConvertible
-
Physics body shape.
Declaration
Swift
open var physicsShape: PhysicsShape
-
▶︎bounds
Returns 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
data
SKTilesetData
tile data.Return Value
SKTile
tile sprite. -
Default initializer.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)
Parameters
aDecoder
decoder 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
tileSize
CGSize
tile size in pixels.Return Value
SKTile
tile sprite. -
Initialize the tile texture.
Declaration
Swift
public init(texture: SKTexture?)
Parameters
texture
SKTexture?
tile texture.Return Value
SKTile
tile sprite. -
Draw the tile. Force the tile to update its textures.
Declaration
Swift
open func draw(debug: Bool = false)
Parameters
debug
Bool
debug draw.
-
Set up the tile’s dynamics body.
Declaration
Swift
open func setupPhysics(shapeOf: PhysicsShape = PhysicsShape.rectangle, isDynamic: Bool = false)
Parameters
shapeOf
PhysicsShape
tile physics shape type.isDynamic
Bool
physics 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
rectSize
CGSize
rectangle size.isDynamic
Bool
physics 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
withSize
CGFloat
rectangle size.isDynamic
Bool
physics 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
radius
CGFloat
circle radius.isDynamic
Bool
physics body is active. -
Remove tile physics body.
Declaration
Swift
open func removePhysics()
Parameters
withSize
CGFloat
dynamics body size.
-
Run tile animation.
Declaration
Swift
open func runAnimation()
-
Remove tile animation.
Declaration
Swift
open func removeAnimation(restore: Bool = false)
Parameters
restore
Bool
restore 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
restore
Bool
restore the tile’s first texture.
-
Set the tile overlap amount.
Declaration
Swift
open func setTileOverlap(_ overlap: CGFloat)
Parameters
overlap
CGFloat
overlap 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
deltaTime
TimeInterval
update interval.
-
▶︎opacity
Opacity value of the tile.
Declaration
Swift
open var opacity: CGFloat { get set }
-
▶︎visible
Tile 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 }