5 ms·
Show HN: Flappy Block – Flappy Bird clone using the iOS7 Physics Engine
- awhitty 13y agoI'm just going to point to FlapFlap [1] as well though it doesn't look like collisions are implemented yet. [1]: https://github.com/nathanborror/FlapFlap https://github.com/nathanborror/FlapFlap
- joeblau 13y agoThat is a great implementation. It seems like Nathan is using SpriteKit while my implementation uses UIDynamics. I just ran it and it seems to have collisions implemented. Mine doesn't have counters or anything extra on the screen yet, but the main challenge for me was playing with the physics engine.
- awhitty 13y agoWow! He has come pretty far in one day. When I cloned it this morning, it was just a bunch of rectangles rendered to the screen.
- jyothepro 13y agois it possible to have both sprite kit and UIkitdynamics together
- hboon 13y agoIf you use SpriteKit, you have access to the other physics engine. And you should use that.
- jey 13y agoWhat do you mean by "iOS7 physics engine"? I can't imagine a game physics engine being included with the OS. Is this referring to a creative abuse of iOS UI widget animations?
- interpol_p 13y agoThere are two physics engines in iOS 7. SpriteKit - Contains a 2D physics engine similar to Box 2D but not as full featured (joints, rigid bodies, shapes, polygons). The whole engine is similar to Cocos2D but ships with iOS 7. A particle editor and texture atlas generator is now built-in to Xcode because of it. UI Dynamics - Contains a set of constraints and joints which can be used to flip and throw views around the screen. Lots of API hooks for responding to / taking user interaction into account. This is used for effects like when you scroll the messages list (the message bubbles bounce and collide) or when you drop notification center down (it bounces). Edit: from a brief look at the source code, this example uses the UIDynamicAnimator API, so it is simulated entirely with the UI dynamics stuff.
- joeblau 13y agoThis is correct. It's all UIDynamicsAnimators using Pushes, Collisions, and Gravity.
- seivan 13y agoSpriteKit itself isn't a physics engine, it comes with one Also, the Physics Engine isn't 'similar' to Box 2D - it _IS_ Box 2D with an OBJ-C wrapper. Same thing applies to UIKit Dynamics, except it plays along with UIKit stuff.
- interpol_p 13y agoYes, that's what I meant when I said SpriteKit contains an engine similar to Box 2D. I thought my comment was reasonably clear about SpriteKit not just being the physics engine. According to my tests it is not Box 2D, it produces significantly different results and only implements a subset of functionality. I've been told by others with more experience that it isn't Box 2D also, but if you have more information I'd like to know for sure.
- ceve 13y agoIf you look at this dump, you can see references to b2World, b2Body etc, https://ghostbin.com/paste/tm4ko https://ghostbin.com/paste/tm4ko
- okamiueru 13y agoI only heard about Flappy Bird today because of the personal story around why it was taken down. However, this seems like just a remake of the helicopter game, which is fair enough, but hardly a feat of engineering. So, if this is the case, then what is this about using a "physics engine"? Determining if rectangles intersect seems a bit too trivial to me to be of interest, and I'm just confused what it is doing here.
- joeblau 13y agoIn iOS7, Apple introduced a new physics engine called UIDynamics. It's built natively into the OS which allows you to give any UIView on the screen physical properties such as Snap, Gravity, Collision, Attachments, and Pushing. Those properties, in turn, have settings like friction, density, gravitational pull, damping, elasticity, etc... The idea behind it was to make it so that you could create game style physics mechanics in any iOS application. One example is the iOS7 notification center; If you drag it down and "slam" it to the bottom of the screen, it has some bounce. A second example is the Messages chats when scrolling quickly; You'll notice that as the swipe seed increases you get more space between peoples chat comments and they kind of slam together when you stop scrolling. What I aimed to do here is take that same engine and use it to build FlappyBlock. So instead of having a loop that says: while () { // Pipe is not on the left movePipeOnePixelLeft(); // Move Pipe one pixel over if (at the left) break; // If we hit the left, end loop } Physics would say something like this: givePipeMassAndLocation(); // Give Pipe physical properties pushPipeLeftWithForceVector(); // Push pipe to left with force whenPipeHitsLeftWallRemove(); // Remove the pipe when it his the left It's a different way of attacking the same problem using features many newer developers are not familiar with in iOS7.