TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Flappy Bird in Swift

309 pointsby pjvdsalmost 11 years ago

26 comments

gokhanalmost 11 years ago
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.
评论 #7839976 未加载
pajjualmost 11 years ago
I just started exploring the Book: The Swift Programming Language by Apple Inc.<p>Link: <a href="https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11" rel="nofollow">https:&#x2F;&#x2F;itunes.apple.com&#x2F;us&#x2F;book&#x2F;the-swift-programming-langu...</a><p>Hope it helps.
评论 #7839158 未加载
评论 #7839153 未加载
kevinwangalmost 11 years ago
I guess Flappy Bird is now a tier 2 &quot;hello world&quot; :)
评论 #7839184 未加载
评论 #7839108 未加载
评论 #7838858 未加载
jashmennalmost 11 years ago
Author here - I didn&#x27;t expect to see this here this morning. I&#x27;d intended to write a longer post :)<p>In any case, here&#x27;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&#x27;s wrong.<p>1. To make properties on a class you simply declare the variable on the class e.g.:<p><pre><code> class GameScene: SKScene { var bird = SKSpriteNode() &#x2F;&#x2F; ... } </code></pre> 2. The APIs generally have shorter names and it&#x27;s really nice. E.g.<p><pre><code> SKTexture* birdTexture1 = [SKTexture textureWithImageNamed:@&quot;Bird1&quot;]; </code></pre> becomes<p><pre><code> var birdTexture1 = SKTexture(imageNamed: &quot;Bird1&quot;) </code></pre> 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:<p><pre><code> var flap = SKAction.repeatActionForever(animation) </code></pre> 3. You can put inline blocks and it&#x27;s great<p><pre><code> var spawn = SKAction.runBlock({() in self.spawnPipes()}) </code></pre> 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&#x27;re using compatible types. e.g.<p><pre><code> var quarter = UInt32( self.frame.size.height &#x2F; 4 ) var y = arc4random() % quarter + quarter; </code></pre> If we didn&#x27;t use `UInt32` to convert `quarter` we&#x27;d get an error. After you get the hang of this, it&#x27;s actually really nice.<p>5. I use `var` everywhere and I&#x27;m pretty sure I should be using `let` a lot more. I haven&#x27;t worked with Swift enough to have a strong intuition about when to use either.<p>I should also mention that my code is just converted from Matthias Gall&#x27;s code [1].<p>I also want to put in a shameless plug that the point of making this was to advertise the &quot;Making Games with Swift&quot; class that auser and I are building. If you&#x27;re interested, put in your email here: <a href="https://fullstackedu.com" rel="nofollow">https:&#x2F;&#x2F;fullstackedu.com</a><p>I intend to redo this more fully with Playgrounds. I&#x27;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&#x27;ve been waiting for.<p>[1] <a href="http://digitalbreed.com/2014/how-to-build-a-game-like-flappy-bird-with-xcode-and-sprite-kit" rel="nofollow">http:&#x2F;&#x2F;digitalbreed.com&#x2F;2014&#x2F;how-to-build-a-game-like-flappy...</a><p>[2] <a href="http://www.fullstack.io/choc/" rel="nofollow">http:&#x2F;&#x2F;www.fullstack.io&#x2F;choc&#x2F;</a><p>EDIT: added choc
评论 #7840916 未加载
评论 #7840063 未加载
评论 #7843030 未加载
评论 #7842973 未加载
matthewmacleodalmost 11 years ago
Good work. I&#x27;ll have to do 2048 instead, I guess :)<p>I&#x27;m quite impressed so far. Having been an Objective C and Ruby engineer, so far Swift seems to offer the best of both.<p>That said, OpenGL support doesn&#x27;t appear to be finished yet.
stigialmost 11 years ago
If you&#x27;re new to functional programming styles this swift project might be more relevant: <a href="https://github.com/maxpow4h/swiftz" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;maxpow4h&#x2F;swiftz</a>
diminishalmost 11 years ago
I got mixed feelings about the language at first sight. I guess my mammalian brain recognizes languages based on the particular combination of the following naming decisions.<p>* func, function, fun, defun fu, funct<p>* CamelCase vs snake_case<p>* whitespace, semicolon or comma usage<p>* var, int&#x2F;integer&#x2F;uint64&#x2F;Integer&#x2F;<p>* choice of (), {}, [] or better (){a[]}<p>* import&#x2F;include&#x2F;require, class&#x2F;class, override, self vs this, new vs Class()<p>PS: next time you design a new language just make a random unique combination of the above.
评论 #7839336 未加载
评论 #7841420 未加载
kclayalmost 11 years ago
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.
评论 #7839856 未加载
评论 #7842467 未加载
LukeB_UKalmost 11 years ago
From the GIF in the readme, it looks like collision detection is broken.
评论 #7841135 未加载
ajanuaryalmost 11 years ago
This being the only code sample of swift I&#x27;ve seen, my overriding takeaway is that for the basic stuff it&#x27;s remarkably similar to Objective-C with a lick of paint.<p>If people really take to swift, it&#x27;ll be interesting to see if that&#x27;s because it creates a shift in programming style, or because people really are just afraid of small syntactical differences.
评论 #7840191 未加载
评论 #7840135 未加载
评论 #7839163 未加载
评论 #7839134 未加载
QuadDamagedalmost 11 years ago
I am really intrigued by the obj-c interop capability of swift, namely interactions between blocks and closures &#x2F; anonymous functions.<p>I can see my AFNetworking code becoming much, much more readable now, without the need to @weakify&#x2F;@strongify self on both sides of the block, but just add a blanket &#x27;[unowned self] in&#x27; inside the closure.
barrystaesalmost 11 years ago
Swift is a new programming language. Does this implementation also use Metal? What is the Scene Kit relation to Metal?
评论 #7839570 未加载
评论 #7838831 未加载
k-mcgradyalmost 11 years ago
This may be a stupid question but is the language in some way tailored to game programming? Apple&#x27;s examples at WWDC were game companies, their coding demo was a game, and this is the first project I&#x27;ve seen written in it - and it&#x27;s a game.
评论 #7839320 未加载
评论 #7840146 未加载
评论 #7840903 未加载
ktgalmost 11 years ago
Flappy Bird in Racket | <a href="https://github.com/soegaard/flappy-bird" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;soegaard&#x2F;flappy-bird</a>
评论 #7841905 未加载
kayoonealmost 11 years ago
pretty neat! I am not an iOS developer but if i understand correctly this uses the new Sprite Kit stuff included in iOS8 for 2d rendering right ? Is this a threat to existing 2d&#x2F;game engines ? Not sure where SpriteKit integrates into the existing stack for making a game.
评论 #7838793 未加载
评论 #7838751 未加载
alexcrooxalmost 11 years ago
Well that didn&#x27;t take long...
Zelphyralmost 11 years ago
If Swift has namespaces why are classes still prefixed? &quot;SKScene&quot; for example.
评论 #7843253 未加载
bradoralmost 11 years ago
Does this need IOS8 to run?<p>Is there a way to get that without being a signed up dev with Apple?
评论 #7840029 未加载
评论 #7838989 未加载
评论 #7839897 未加载
seanhandleyalmost 11 years ago
Someone needs to add Swift to the linguist gem
martinvolalmost 11 years ago
OK, that was fast!
joeyspnalmost 11 years ago
2k+ Github stars in less than 24h? OMG
hellbreakslosealmost 11 years ago
Swift looks fine, the only thing I don&#x27;t like its that is for Apple only products... that kinda defeats the purpose of having a programming language.
评论 #7839909 未加载
评论 #7840701 未加载
评论 #7839237 未加载
评论 #7842828 未加载
评论 #7839597 未加载
napoluxalmost 11 years ago
FAST AS HELL! :P Thanks a lot!
supergeek133almost 11 years ago
Why.
nakovetalmost 11 years ago
I was curious when I saw a tests folders, but it was just auto-generated files with no actual tests. =(
评论 #7839879 未加载
nicolimealmost 11 years ago
Share the latest about Swift here! Be part of the biggest page for the language. Looking for admins. <a href="https://www.facebook.com/swiftofficial" rel="nofollow">https:&#x2F;&#x2F;www.facebook.com&#x2F;swiftofficial</a>