Skip to content

clns/spritekit-atlas-batching

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

SpriteAtlas draw calls NOT batched

Sample Xcode 13 project using a Sprite Atlas inside an Assets Catalog.

  • When using the SKTextureAtlas(named:) initializer to load the texture atlas from data stored in the app bundle, the draw calls are not batched.
  • When using the SKTextureAtlas(dictionary:) initializer to create a texture atlas from a set of image files, the draw calls are batched.

Related questions:

Visual

Here, there are 2 draw calls, one for each sprite node:

Draw calls not batched with SpriteAtlas

Here, there is only 1 draw call, batched:

Draw calls batched with SpriteAtlas

The SpriteAtlas in the Assets Catalog:

SpriteAtlas in the Assets Catalog

The code is very simple, in GameScene.swift:

import SpriteKit

class GameScene: SKScene {
    
    override func didMove(to view: SKView) {
        let atlas = SKTextureAtlas(named: "Sprites")
//        let atlas = SKTextureAtlas(dictionary: ["costume": UIImage(named: "costume")!, "tank": UIImage(named: "tank")!])
        
        let costume = SKSpriteNode(texture: atlas.textureNamed("costume"))
        costume.setScale(0.3)
        costume.position = CGPoint(x: 200, y: 650)
        
        let tank = SKSpriteNode(texture: atlas.textureNamed("tank"))
        tank.setScale(0.3)
        tank.position = CGPoint(x: 500, y: 650)
        
        addChild(costume)
        addChild(tank)
    }
}

About

Sample Xcode 13 project using SpriteKit's Sprite Atlas to show draw calls not being batched when using the atlas created by Xcode.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages