3 ms·
In 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 pr
by joeblau 13y ago
In 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.