12 ms·
Flappy Bird in Swift
- kayoone 12y agopretty 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/game engines ? Not sure where SpriteKit integrates into the existing stack for making a game.
- austinz 12y agoSpriteKit was released last year with iOS 7. It's a pretty much self-contained 2D game engine like Cocos2D, including stuff like physics simulation. iOS 8 is going to ship with SceneKit, which is similar but for simple 3D games.
- yowmamasita 12y agoHow extensive is the physics engine implementation?
- austinz 12y agoWikipedia claims that SpriteKit uses the Box2D engine internally: http://en.wikipedia.org/wiki/Box2D http://en.wikipedia.org/wiki/Box2D
- coldcode 12y agoIn iOS7 it is Box2d, but not all of it was implemented. There is likely a lot more now in iOS8. There is also a 3d version which I assume uses Box3d.
- babuskov 12y agoLooks like a good way for Apple to lock the developers to their platform. In past glory days people used to make games for iOS first and consider porting to Android much later. These days developers think cross-platform from the start, esp. since it's much easier to test waters and iterate on Android. I guess that SpriteKit is an attempt to stop this trend. Smart move by Apple IMHO, but perhaps a little bit too late.
- chillingeffect 12y agoI see your polite, critical, level-headed opinion has been down voted into gray dust, despite my meager support. I entreat those who pass by here to drink in my own following opinion: I think you're operating from the democratic ideal that "all people will opine equally about all topics at all times." The departure from this ideal, I've discovered, is that there is a "Practical Crowd" who will swoop through when questions of practicality, such as cross-platform compatibility come up. Their opinions will be nearly absolute and they will be all but intolerant of the "weak" who claim that merely targeting Windows, Linux and OSX is "enough." They will justify with numerous cherry-picked examples from history, starkly, if not carefully, considered arguments toward the future, and with evidence of grit on their fingers from the present, in which the particular ideal is espoused. At that time, they will down vote anyone deviant enough to cheer for Swift. Yet, currently my friend, the Apple Crowd has the floor. Any practical concerns are scheduled after the celebration. Think of this when you read the next cross-platform thread and see the Apple fans trying to get a point in edgewise amongst The Practical. There is very little global reality, mainly local basins of morality.
- barrystaes 12y agoSwift is a new programming language. Does this implementation also use Metal? What is the Scene Kit relation to Metal?
- diminish 12y agoI 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. * func, function, fun, defun fu, funct * CamelCase vs snake_case * whitespace, semicolon or comma usage * var, int/integer/uint64/Integer/ * choice of (), {}, [] or better (){a[]} * import/include/require, class/class, override, self vs this, new vs Class() PS: next time you design a new language just make a random unique combination of the above.
- fdej 12y ago> 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?
- jaxytee 12y agoBecause in this case, it's an alternative to a language (Objective C) with a not so boring esoteric syntax.
- annnnd 12y agoNot boring at all - but I'm not sure this helps adoption any. :)
- Illotus 12y agoIt would be pretty weird to base language switching decision on syntax similarity.
- collyw 12y agoDo you see the amount of people that complain about Pythons white space? Plenty of people avoid it for that reason alone.
- pjc50 12y ago
- kevinwang 12y agoI guess Flappy Bird is now a tier 2 "hello world" :)
- Fuxy 12y agoIt certainly would be cool if it were.
- misnome 12y agoI was disappointed that they didn't use it as "The simplest possible game" in the WWDC presentation
- dylz 12y agoCopyright...
- zapu 12y agoIs it really copyrighted though?
- masukomi 12y agoyes. IANAL but... copyright law in the US is such that, in essence, everything is copyrighted (to some degree) the moment it is created unless you explicitly state otherwise. When dealing with anything legally distributed / created in the US there are many questions, but "is it copywritten" should be one of the last ones, because the answer is always YES.
- nicolime 12y agoShare the latest about Swift here! Be part of the biggest page for the language. Looking for admins. https://www.facebook.com/swiftofficial https://www.facebook.com/swiftofficial
- brador 12y agoDoes this need IOS8 to run? Is there a way to get that without being a signed up dev with Apple?
- alexbilbie 12y agoIt shouldn't need iOS 8 to run because it compiles down to the same native code that Objective-C apps and Rubymotion apps do.
- craigching 12y ago> 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.
- martingordon 12y agoApple 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.
- LukeB_UK 12y agoFrom the GIF in the readme, it looks like collision detection is broken.
- jashmenn 12y agoI'm terrible at flappy bird - I can /sometimes/ get through the first pipe. Rarely. I didn't build the collision detection yet just b/c I actually think it's more fun to play this way. That said, we'll add it before too long.
- alexcroox 12y agoWell that didn't take long...
- stigi 12y agoIf you're new to functional programming styles this swift project might be more relevant: https://github.com/maxpow4h/swiftz https://github.com/maxpow4h/swiftz
- napolux 12y agoFAST AS HELL! :P Thanks a lot!
- ajanuary 12y agoThis 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.
- threeseed 12y agoSwift is definitely more approachable than Objective-C for new developers. I would imagine that is very on the reasons for creating it.
- ajanuary 12y agoFor new developers, or for developers coming from other languages? I think a lot of the trouble people have with starting to develop apps for Apple platforms actually comes from trying to figure out the APIs and style, while at the same time battling against unfamiliar syntax. From the little I've seen, Swift doesn't change the first part of that very much.
- threeseed 12y agoBoth. The APIs and style sure are issues. But there are plenty of language constructs which exist only in Objective-C.
- eddieroger 12y agoI think both. I have a young cousin who is starting to show interest in programming, and when I think of showing her Objective-C, I grimace inside because it has taken me so long to become comfortable with it, and I'm coming from other languages and years of experience. But I think I can walk through Swift with her, and we can learn it at the same time - me bridging the gaps because I come from another language, and her learning how to program for the first time.
- andybak 12y agoReadability matters - maybe the Objective-C verbiage melts away once you're up to speed, but it certainly puts you off wanting to get there.
- pajju 12y agoI just started exploring the Book: The Swift Programming Language by Apple Inc. Link: https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11 https://itunes.apple.com/us/book/the-swift-programming-langu... Hope it helps.
- zura 12y agoCan anybody put this book somewhere outside itunes? Thanks!
- klapinat0r 12y agohttps://news.ycombinator.com/item?id=7835994 https://news.ycombinator.com/item?id=7835994
- damncabbage 12y agoAnd the same, in HTML form: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/index.html#//apple_ref/doc/uid/TP40014097-CH3-XID_0 https://developer.apple.com/library/prerelease/ios/documenta...
- tvon 12y agoNote that near the top of "A Swift Tour" there is a link to the playground which you can download and open in Xcode 6.
- discohead 12y agoWow, that is cool. Learning Swift is going to be fun. Direct link to the playground file: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.playground.zip https://developer.apple.com/library/prerelease/ios/documenta...
- seanhandley 12y agoSomeone needs to add Swift to the linguist gem
- matthewmacleod 12y agoGood work. I'll have to do 2048 instead, I guess :) I'm quite impressed so far. Having been an Objective C and Ruby engineer, so far Swift seems to offer the best of both. That said, OpenGL support doesn't appear to be finished yet.
- hellbreakslose 12y agoSwift 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.
- unfamiliar 12y agoYou can write code for non-apple products, its just that the libraries are lacking. I don't see how this defeats "the purpose of a programming language".
- mnem 12y agoGood luck compiling Objective-C on Windows :)
- mdellabitta 12y agoPretty sure you can compile Objective-C on Windows, since gcc supports it, and OpenStep worked on Windows. It's Apple's libraries you don't get on Windows.
- matthewmacleod 12y agoHere you go: http://www.gnustep.org/experience/Windows.html http://www.gnustep.org/experience/Windows.html
- mnem 12y agoYe-es, except: "Apple has recently added new functionality to their runtime, including built-in exception handling, etc. Hopefully these will be ported to the GNU runtime in the future." My general point is that programming languages don't have to be cross platform to be useful. Certainly handy from a developer's point of view, but just a convenience.
- craigching 12y ago> 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 ;)
- k-mcgrady 12y agoThis may be a stupid question but is the language in some way tailored to game programming? Apple's examples at WWDC were game companies, their coding demo was a game, and this is the first project I've seen written in it - and it's a game.
- ajanuary 12y agoGames make easy examples because you can do a simple render loop and input. Most people understand the concept of sprites and basic animation. Apple's UI frameworks are all MVC based, which means multiple classes and apple specific UI terminology.
- eddieroger 12y agoAdditionally, they're a quick route between code and something visual. If the demo yesterday had been "look how easy I can make a tableview", no one would have cared much, but the circus scene had motion, lights, and barely any code. People love spectacle. That reads a lot more sarcastic than it should have, but it's unfortunately true. Swift was announced in front of a room of people who needed to be convinced to start migrating from something they all know (ObjC) in favor of something new, so you have to win them over quick.
- mitchty 12y agoI think you're missing this is building off of other things that are meant for games like scene kit etc.... The language isn't tailored to it, but there are things it makes easy that are. If that makes any sense.
- wging 12y agoThere's also a new graphics API, 'Metal', though I don't know if that has anything to do with it.
- QuadDamaged 12y agoI am really intrigued by the obj-c interop capability of swift, namely interactions between blocks and closures / anonymous functions. I can see my AFNetworking code becoming much, much more readable now, without the need to @weakify/@strongify self on both sides of the block, but just add a blanket '[unowned self] in' inside the closure.
- nakovet 12y agoI was curious when I saw a tests folders, but it was just auto-generated files with no actual tests. =(
- craigching 12y agoSwift hasn't even been out for 24 hours yet, give the guy a break! ;)
- gokhan 12y agoAs 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.
- matthewmacleod 12y agoI 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.
- WorldWideWayne 12y agoThat's my problem. I can't even find the entry point for this application. Looking at AppDelegate.swift I see an unused var (window) and that's it.
- matthewmacleod 12y ago@UIApplicationMain is the key there, from what I can see. An Objective C iOS app typically includes a main.m entry point which calls UIApplicationMain and passes the AppDelegate. This seems to have been removed in favour of what Swift is calling a "declaration attribute", which presumably does the same thing. In this sense, the code is even less clear than the Objective C implementation.
- sAuronas 12y agoThey removed the need for main by making global scope the entry point.
- untog 12y agothe barrier is totally psychological Of course it is. It's certainly not a physical barrier. But psychological or not, other languages don't have a similar barrier.
- kclay 12y agoAlways 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.
- craigching 12y agoYes, you still need a Mac to develop for iOS. Come to the dark side! :)
- bigtunacan 12y agoWe have cookies.
- viiralvx 12y agoAndroid developer here with a Macbook Pro. I'm honestly thinking about taking the leap and getting an iPhone, depending on how the 6 looks like. But Swift enticed me very much.
- herinkc 12y agoYou won't regret it
- Tokala 12y agoWhat is so hard about reading Objective-C? I've seen this as a very common thread with people celebrating the arrival of Swift. I'm not trying to be flippant and I understand that the named parameter format may throw some people for a loop, but I'm curious why it appears to be such a limiting factor in trying Objective-C.
- jashmenn 12y agoAuthor 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 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-bird-with-xcode-and-sprite-kit http://digitalbreed.com/2014/how-to-build-a-game-like-flappy... [2] http://www.fullstack.io/choc/ http://www.fullstack.io/choc/ EDIT: added choc
- kevin818 12y agoI 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!
- supergeek133 12y agoWhy.
- deleted 12y ago[deleted]
- ktg 12y agoFlappy Bird in Racket | https://github.com/soegaard/flappy-bird https://github.com/soegaard/flappy-bird
- dukerutledge 12y agoMan, apparently dr racket format looks like a hot mess.
- soegaard 12y agoA normal Racket file is a straight forward text file. In Flappy Bird I used inline images, as in (define bird <the-bird-image-here> ) This makes it simple to distribute the source and images as a single file, but unfortunately the resulting file is not pretty. In short: to see the source open it in DrRacket.
- joeyspn 12y ago2k+ Github stars in less than 24h? OMG
- martinvol 12y agoOK, that was fast!
- Zelphyr 12y agoIf Swift has namespaces why are classes still prefixed? "SKScene" for example.
- rys 12y agoObjective-C interop.