efe_ertugrul

apple developer

home tech_notes app_store github stackoverflow devto

Getting Started with Sprite Nodes


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

Overview

The simplest way to create a textured sprite node is to have SpriteKit create both the texture and the sprite for you. You store the artwork in the app bundle (ideally in an asset catalog), and then load it at runtime, as shown in this code:

let spaceship = SKSpriteNode(imageNamed: "rocket.png")
spaceship.position = CGPoint(x: 100, y: 100)
self.addChild(spaceship)

Default Behavior

When you create a sprite as shown in the code above, you get a lot of default behavior for free:

Textures

Although SpriteKit can create textures for you automatically when a sprite is created, in more complex apps you need finer control over textures. For example, you might want to do any of the following:

You do all of these things by working directly with texture objects. For more information, see the SKTexture class reference.

Customized Rendering Stages

You can use each sprite node’s properties to independently configure four distinct rendering stages:

Art and Property Configuration Matching

Often, configuring a sprite node to perform these four steps—positioning, sizing, colorizing, and blending—is based on the artwork used to create its texture. This means that you rarely set property values in isolation from the artwork. You work with your artist to ensure that your game is configuring the sprites to match the artwork.

Here are some of the possible strategies you can follow:


download this page as .md

download this page as .pdf

back to SpriteKit documentation