Class

SKSpriteNode

An image or solid color.

Declaration

@interface SKSpriteNode : SKNode

Overview

SKSpriteNode is an onscreen graphical element that can be initialized from an image or a solid color. SpriteKit adds functionality to its ability to display images using the functions discussed below.

Topics

Creating a Sprite from an Image Filename

Start with the basic ways to configure and use a sprite node.

Getting Started with Sprite Nodes

Learn the basics about using images, also known as sprites, with SpriteKit.

- initWithImageNamed:

Initializes a textured sprite using an image file.

+ spriteNodeWithImageNamed:normalMapped:

Initializes a textured sprite using an image file, optionally adding a normal map to simulate 3D lighting.

Creating a Sprite from a Texture

Reuse a texture across multiple sprite nodes using initializers or the setter.

- initWithTexture:

Initializes a textured sprite using an existing texture object.

- initWithTexture:color:size:

Initializes a colored and textured sprite using an existing texture object.

+ spriteNodeWithColor:size:

Initializes a colored sprite.

+ spriteNodeWithImageNamed:

Initializes a textured sprite using an image file.

+ spriteNodeWithTexture:

Initializes a textured sprite using an existing texture object.

+ spriteNodeWithTexture:size:

Initializes a textured sprite using an existing texture object but with a specified size.

+ spriteNodeWithTexture:normalMap:

Initializes a textured sprite with a normal map to simulate 3D lighting.

texture

The texture used to draw the sprite.

Creating a Solid Colored Sprite

Create a colored block of any size that's also useful for visual debugging.

- initWithColor:size:

Initializes a colored sprite node.

Initializing a Sprite from an Archive

- initWithCoder:

Tells you when to initialize a sprite from an archive.

Setting a Sprite's Size and Position

Control a sprite's onscreen placement and size.

Using the Anchor Point to Move a Sprite

Learn how the anchor point affects a sprite's position.

size

The dimensions of the sprite, in points.

- scaleToSize:

Scales the sprite node to a specified size.

anchorPoint

Defines the point in the sprite that corresponds to the node’s position.

Scaling a Sprite in Nine Parts

Resize a sprite in nine parts by defining a center rectangle.

Resizing a Sprite in Nine Parts

Scale a sprite using nine-part algorithm.

centerRect

Enable nine-part stretching of the sprite's texture.

Tinting a Sprite

Combine color and blend factor properties to colorize a textured sprite.

Tinting a Sprite

Provide a color and blend factor to additively color your sprite.

color

The sprite’s color.

colorBlendFactor

A floating-point value that describes how the color is blended with the sprite’s texture.

Configuring Alpha Blendling

Determine how a sprite uses an alpha value, such as additive blending, that results in the sprite being brighter than it was before.

Blending a Sprite with Different Interpretations of Alpha

Reinterpret a sprite's alpha property to react differently to the objects below it.

blendMode

The blend mode used to draw the sprite into the parent’s framebuffer.

SKBlendMode

The modes that describe how the source and destination pixel colors are used to calculate the new destination color.

Lighting a Sprite

Configure how a sprite is lit when it's near a light node.

Lighting a Sprite with Light Nodes

Add lighting and shadows to your scene with light nodes.

lightingBitMask

A mask that defines how this sprite is lit by light nodes in the scene.

shadowedBitMask

A mask that defines which lights add shadows to the sprite.

shadowCastBitMask

A mask that defines which lights are occluded by this sprite.

normalTexture

A texture that specifies the normal map for the sprite.

Adding a Custom Shader to a Sprite

Supply a code file that does custom per-pixel rendering or colorization of a sprite.

Applying Shaders to a Sprite

Write custom GLSL code that modifies the look of your sprite.

shader

A text file that defines code that does custom per-pixel drawing or colorization.

attributeValues

The values of each attribute associated with the node's attached shader.

- setValue:forAttributeNamed:

Sets an attribute value for an attached shader.

- valueForAttributeNamed:

Sets the value of a shader attribute.

Animating a Sprite by Changing its Texture

Animating a Sprite by Changing its Texture

Load a sequence of images and play them back at a rate you define, while optionally looping the resulting animation.

Relationships

Inherits From

Conforms To

See Also

Nodes that Draw

Maximizing Node Drawing Performance

Structure your nodes for maximum performance.

SKShapeNode

A mathematical shape that can be stroked or filled.

SKEmitterNode

A source of various particle effects.

SKLabelNode

A graphical element that draws text.

SKVideoNode

A graphical element that plays video content.

SKTileMapNode

A two-dimensional array of images.

SK3DNode

3D SceneKit content drawn as a flattened sprite.