Skip to content

Instantly share code, notes, and snippets.

@sarah-j-smith
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarah-j-smith/06271882feb77ce93849 to your computer and use it in GitHub Desktop.
Save sarah-j-smith/06271882feb77ce93849 to your computer and use it in GitHub Desktop.
Swift+SpriteKit does a good job with its default string descriptions of nodes; so just do something like this to get a nice log dump of your scene

Usage

Call with myScene.printNodeTree()

Example Output

Scene (SKView ignores sibling order)
<SKScene> name:'Game Scene' frame:{{0, 0}, {768, 1024}}
    <SKNode> name:'Background Layer' position:{0, 0} accumulatedFrame:{{96, 0}, {576, 1024}}
       > frame: (0.0, 0.0, 0.0, 0.0)
        <SKSpriteNode> name:'CityBackground' texture:[<SKTexture> 'CityBackground' (1242 x 2208)] position:{384, 512} size:{576, 1024} rotation:0.00
           > frame: (96.0, 0.0, 576.0, 1024.0)
    <SKNode> name:'Gameplay Layer' position:{0, 0} accumulatedFrame:{{0, 0}, {672.25, 1004.79052734375}}
       > frame: (0.0, 0.0, 0.0, 0.0)
        <WordMonsters.Carousel> name:'(null)' position:{384, 572} accumulatedFrame:{{0, 0}, {613.5, 1004.79052734375}}
           > frame: (384.0, 572.0, 0.0, 0.0)
            <SKShapeNode> name:'(null)' accumulatedFrame:{{-384, -572}, {613.5, 701.75}}
               > frame: (-384.0, -572.0, 613.5, 701.75)
            <SKShapeNode> name:'(null)' accumulatedFrame:{{-384, -572}, {613.5, 572}}
               > frame: (-384.0, -572.0, 613.5, 572.0)
            <SKShapeNode> name:'(null)' accumulatedFrame:{{-384, -572}, {519.21685791015625, 1004.79052734375}}
               > frame: (-384.0, -572.0, 519.216857910156, 1004.79052734375)
        <WordMonsters.TentacleMonster> name:'Tentacle' position:{469.26263427734375, 916.6705322265625} accumulatedFrame:{{457.40631103515625, 900.90789794921875}, {24.471893310546875, 24.00164794921875}}
           > frame: (469.262634277344, 916.670532226562, 0.0, 0.0)
            <SKSpriteNode> name:'MonsterBody' texture:[<SKTexture> 'tentacle-monster-body@2x.png' (307 x 199)] position:{0, 0} size:{153, 100} rotation:0.00
               > frame: (-70.0211715698242, -48.9949760437012, 143.032577514648, 98.4924621582031)
                <SKSpriteNode> name:'Tentacles' texture:[<SKTexture> 'tentacles1@2x.png' (307 x 295)] position:{0.28724002838134766, -24.710567474365234} size:{153, 148} rotation:0.00
                   > frame: (-71.2290420532227, -94.6970062255859, 147.019546508789, 70.7389831542969)
        <WordMonsters.Launchpad> name:'Launchpad' position:{624.25, 0} accumulatedFrame:{{576.75, 0}, {95.5, 331.31314086914062}}
           > frame: (624.25, 0.0, 0.0, 0.0)
            <SKSpriteNode> name:'Launchpad' texture:[<SKTexture> 'MissilePad@2x.png' (190 x 552)] position:{0, 0} size:{95, 276} rotation:0.00
               > frame: (-47.5, 0.0, 94.0, 265.5)
            <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'Missile@2x.png' (256 x 256)] position:{0, 230.91314697265625} size:{128, 128} rotation:0.00
               > frame: (-47.0, 221.813140869141, 95.0, 109.5)
    <SKNode> name:'Effects Layer' position:{0, 0} accumulatedFrame:{{inf, inf}, {inf, inf}}
       > frame: (0.0, 0.0, 0.0, 0.0)
    <SKNode> name:'UI Layer' position:{0, 0} accumulatedFrame:{{108.5, 938}, {72, 73.5}}
       > frame: (0.0, 0.0, 0.0, 0.0)
        <WordMonsters.Button> name:'(null)' position:{142, 977.25} accumulatedFrame:{{108.5, 938}, {72, 73.5}}
           > frame: (142.0, 977.25, 0.0, 0.0)
            <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'settings@2x.png' (128 x 128)] position:{0, 0} size:{64, 64} rotation:0.00
               > frame: (-28.5, -30.5, 57.0, 58.5)
            <SKShapeNode> name:'ButtonShadow: ' accumulatedFrame:{{-30.5, -39.25}, {69, 70.5}}
               > frame: (-30.5, -39.25, 69.0, 70.5)
            <SKShapeNode> name:'ButtonFrame: ' accumulatedFrame:{{-33.5, -34.25}, {67, 68.5}}
               > frame: (-33.5, -34.25, 67.0, 68.5)
Scene (SKView ignores sibling order)
import Foundation
import SpriteKit
public extension SKNode {
func printNodeTree() {
var buffer = ""
if let sceneNode = self as? SKScene {
buffer += "Scene"
if let parentView = sceneNode.view
{
if parentView.ignoresSiblingOrder
{
buffer.extend(" (SKView ignores sibling order)")
}
}
println(buffer)
}
dumpNode(self, atIndent: 0)
println(buffer)
}
func dumpNode(node: SKNode, atIndent indent: Int)
{
let pad : Character = " "
let spaces = String(count: indent * 4, repeatedValue: pad)
println("\(spaces)\(node)")
if node.description.rangeOfString("frame:") == nil
{
println("\(spaces) > frame: \(node.frame)")
}
for child in node.children {
dumpNode(child as! SKNode, atIndent: indent + 1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment