Live data from Hacker News

Flappy Bird in Swift

github.com

61–70 of 126 posts

Re: Flappy Bird in Swift

#61
post #12

Does this need IOS8 to run? Is there a way to get that without being a signed up dev with Apple?

> Is there a way to get that without being a signed up dev with Apple?

You need to be in the iOS developer program to get iOS 8 beta.

Re: Flappy Bird in Swift

#62

Swift looks fine, the only thing I don't like its that is for Apple only products... that kinda defeats the purpose of having a programming language.

> Swift looks fine, the only thing I don't like its that is for Apple only products... that kinda defeats the purpose of having a programming language.

Tell that to Microsoft ;)

Re: Flappy Bird in Swift

#64
post #55

Always had a problem with Objective C, could never read it (Android Dev) but this right here is pretty impressive. I like the mixture of language features. But my only question, are you still locked to using an mac to develop for iOS. I guess since the language is closed source it depends on some osx libs at compile time.

Yes, you still need a Mac to develop for iOS. Come to the dark side! :)

We have cookies.

Re: Flappy Bird in Swift

#65
post #54

As a C# developer, I can read and understand the code without any issues. That's a good thing for Apple. I'm sure Objective-C is great but it's too foreign for me and didn't want to toy with it for fun, not worth the effort. But I can write an app or two with this one.

I get where you're coming from - but in my experience, the barrier is totally psychological. Objective C isn't that unusual a language - the syntax is a bit foreign, but nothing that takes more than a couple of days to wrap your head around.

You'll spend far more time getting to grips with Cocoa/Cocoa Touch.

Re: Flappy Bird in Swift

#66
post #41
post #38

Earlier quoted context omitted.

> PS: next time you design a new language just make a random unique combination of the above. That's my impression whenever I see a new programming language too. Why would someone switch to your language if the syntax is just the same boring old syntax they've been using in another language?

Because in this case, it's an alternative to a language (Objective C) with a not so boring esoteric syntax.

Not boring at all - but I'm not sure this helps adoption any. :)

Re: Flappy Bird in Swift

#67
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

Re: Flappy Bird in Swift

#68
post #12

Does this need IOS8 to run? Is there a way to get that without being a signed up dev with Apple?

Apple has stated that Swift apps can target iOS 7/8 and Mavericks/Yosemite. You do need access to the dev program in order to get access to the Xcode 6 beta.

Re: Flappy Bird in Swift

#69

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 = SKSpriteN…

I think just the fact that you were able to build a game with just 4 hours of learning a new language speaks volumes about Swift's barrier to entry. Well done!

Re: Flappy Bird in Swift

#70

This being the only code sample of swift I've seen, my overriding takeaway is that for the basic stuff it's remarkably similar to Objective-C with a lick of paint. If people really take to swift, it'll be interesting to see if that's because it creates a shift in programming style, or because people really are just afraid of small syntactical differences.

Part of the reason it looks like that is because I don't really know swift all that well. One of the great things we have in Swift is more functional features like closures, named functions, etc. I expect we'll see a lot of higher-order functions being used and that would clean it up a lot.
Post reply on HN