Topic:   Swift Playground   (Read 8591 times)


0 Members and 1 Guest are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Swift Playground
« on: June 04, 2014, 07:47:11 PM »
I've had some time to play with the Swift Playground. Here's what I gotta say:

It is nice. The purpose of Playground is to test pieces of code. You insert a snippet of code into the playground and you can record however many seconds you want of the code running. Then when it finishes running you can look through the recorded timeline and inspect all variables.

For me, the main use of this will be to test sections of games. Make a Playground for testing an in-game store. Make a playground for testing a battle, make a playground for testing cutscenes. Cause it records all values you can inspect and ensure everything is how you want it. You can even look at all your fancy animations frame-by-frame to ensure perfection.


If you install the beta Xcode you can test out this playground code:
Code: [Select]
import Cocoa
import SpriteKit
import XCPlayground

class GameScene: SKScene {
    var myLabel : SKLabelNode
    var lastTime : Double
   
    init(size: NSSize!) {
        myLabel = SKLabelNode(fontNamed:"Helvetica")
        lastTime = 0
        super.init(size: size)
    }
   
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        myLabel.text = "Some text 2"
        myLabel.fontSize = 64
        myLabel.position = CGPoint(x:CGRectGetMidX(self.frame),         y:CGRectGetMidY(self.frame))
       
        self.addChild(myLabel)
    }
   
    override func update(currentTime: CFTimeInterval) {
        var delta = currentTime - lastTime
        lastTime = currentTime
        if delta > 1 { delta = 1.0/30.0 }
       
        print("\(delta) \n")
        /* Called before each frame is rendered */
        myLabel.zRotation += 0.1;
    }
}

let viewFrame = NSMakeRect(0, 0, 800, 600)
let spriteKitView = SKView(frame: viewFrame)
let spriteKitScene = GameScene(size: NSMakeSize(800, 600))

spriteKitView.presentScene(spriteKitScene)
XCPShowView("GameView", spriteKitView)

I'm going to use this in my latest game. My biggest problem in making my games is that I had to play the game through to test a certain piece. Now I can just test that piece without waiting on my cutscenes and menus.