sprite-kit SKSpriteNode (Sprites) Adding a Sprite to the Scene


In SpriteKit a Sprite is represented by the SKSpriteNode class (which inherits from SKNode).

First of all create a new Xcode Project based on the SpriteKit template as described in Your First SpriteKit Game.

Creating a Sprite

Now you can create a SKSpriteNode using an image loaded into the Assets.xcassets folder.

let spaceship = SKSpriteNode(imageNamed: "Spaceship")

Spaceship is the name of the image item into the Assets.xcassets.

After the sprite has been created you can add it to your scene (or to any other node).

Open GameScene.swift, remove all its content and add the following

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        let enemy = SKSpriteNode(imageNamed: "Spaceship")
        enemy.position = CGPoint(x:self.frame.midX, y:self.frame.midY)

Now press CMD + R in Xcode to launch the Simulator.

enter image description here