| Author here - I didn't expect to see this here this morning. I'd intended to write a longer post :) In any case, here's a few things I learned about swift yesterday building this. Please note that I have about 4 hours swift experience, so feel free to correct anything I say that's wrong. 1. To make properties on a class you simply declare the variable on the class e.g.: class GameScene: SKScene {
var bird = SKSpriteNode()
// ...
}
2. The APIs generally have shorter names and it's really nice. E.g. SKTexture* birdTexture1 = [SKTexture textureWithImageNamed:@"Bird1"];
becomes var birdTexture1 = SKTexture(imageNamed: "Bird1")
If I understand it correctly, any overloading `inits` basically look like calling the constructor on the class, whereas any class functions will be called like this: var flap = SKAction.repeatActionForever(animation)
3. You can put inline blocks and it's great var spawn = SKAction.runBlock({() in self.spawnPipes()})
4. The typing is really strong - this takes some getting used to. For instance, `arc4random()` returns a 32 bit unsigned integer. This means before you can use any operators on it you have to make sure you're using compatible types. e.g. var quarter = UInt32( self.frame.size.height / 4 )
var y = arc4random() % quarter + quarter;
If we didn't use `UInt32` to convert `quarter` we'd get an error. After you get the hang of this, it's actually really nice.5. I use `var` everywhere and I'm pretty sure I should be using `let` a lot more. I haven't worked with Swift enough to have a strong intuition about when to use either. I should also mention that my code is just converted from Matthias Gall's code [1]. I also want to put in a shameless plug that the point of making this was to advertise the "Making Games with Swift" class that auser and I are building. If you're interested, put in your email here: https://fullstackedu.com I intend to redo this more fully with Playgrounds. I've been looking for a way to teach kids programming for a while now (if you recall, auser and I built Choc [2] a few months back). I think Playgrounds in Swift are finally the tool we've been waiting for. [1] http://digitalbreed.com/2014/how-to-build-a-game-like-flappy... [2] http://www.fullstack.io/choc/ EDIT: added choc |