{"id":233,"date":"2014-02-05T16:09:44","date_gmt":"2014-02-05T15:09:44","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=233"},"modified":"2018-05-25T14:02:11","modified_gmt":"2018-05-25T12:02:11","slug":"how-to-make-flappy-bird-like-game-using-uikit","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/","title":{"rendered":"[Objc] How to make Flappy Bird like game using UIKit"},"content":{"rendered":"<p>As explained in the last post, (\u00a0<a href=\"http:\/\/www.albertopasca.it\/whiletrue\/2014\/02\/how-to-make-flappy-bird-like-game-using-cocos2d\/\" target=\"_blank\" rel=\"noopener\">How to make Flappy Bird like game using Cocos2D<\/a>\u00a0) today, we learn how to make a Flappy Bird game using Objectivec SKSpriteKit for iOS7 in 20 rows of code!<\/p>\n<p><!--more--><\/p>\n<h4>What you need?<\/h4>\n<p>XCode and iOS 7 SDK.<br \/>\nOpen XCode, make new project and select SpriteKit Game for iOS or OSX, it\u2019s equal.<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3093\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png?resize=721%2C481\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" srcset=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png 721w, http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57-300x200.png 300w\" alt=\"Screenshot 2014-02-22 01.19.57\" width=\"721\" height=\"481\" \/><\/p>\n<h5>Prepare game graphics<\/h5>\n<p>~ background<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-static.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3096\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-static.png?resize=320%2C568\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" srcset=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-static.png 320w, http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-static-169x300.png 169w\" alt=\"MarioBackground-static\" width=\"320\" height=\"568\" \/><\/a><br \/>\n~ scrollable floor<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3095\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling.png?resize=909%2C120\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" srcset=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling.png 909w, http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling-300x39.png 300w\" alt=\"MarioBackground-scrolling\" width=\"909\" height=\"120\" \/><\/a><br \/>\n~ scrollable sky<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling-top.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3094\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling-top.png?resize=909%2C600\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" srcset=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling-top.png 909w, http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/MarioBackground-scrolling-top-300x198.png 300w\" alt=\"MarioBackground-scrolling-top\" width=\"909\" height=\"600\" \/><\/a><br \/>\n~ the player<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Bird%402x.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3099\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Bird%402x.png?resize=76%2C54\" alt=\"Bird@2x\" width=\"76\" height=\"54\" \/><\/a><br \/>\n~ the pipes (up \/ down)<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/PipeBottom%402x.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3100\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/PipeBottom%402x.png?resize=112%2C112\" alt=\"PipeBottom@2x\" width=\"112\" height=\"112\" \/><\/a><br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/PipeTop%402x.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3101\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/PipeTop%402x.png?resize=112%2C112\" alt=\"PipeTop@2x\" width=\"112\" height=\"112\" \/><\/a><\/p>\n<h4>Making main menu scene<\/h4>\n<p>In your new file, MyScene.m, edit initWithSize method adding some SKSpriteNode, as the background image, the fish, and a SKLabelNode, that is the title.<\/p>\n<p>Very easy to draw:<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]\/\/ add the backgound<br \/>\nSKSpriteNode\u00a0*background\u00a0=\u00a0[SKSpriteNode spriteNodeWithImageNamed:@&quot;MarioBackground-static&quot;];<br \/>\n[background setPosition:CGPointMake(self.frame.size.width\/2, self.frame.size.height\/2\u00a0&#8211;\u00a012)];<br \/>\n[self addChild:background];\/\/ add the title label<\/p>\n<p>SKLabelNode\u00a0*titleLabel\u00a0=\u00a0[[SKLabelNode alloc]\u00a0initWithFontNamed:@&quot;Helvetica&quot;];<br \/>\n[titleLabel setPosition:CGPointMake(self.size.width\/2, self.size.height-150)];<br \/>\n[titleLabel setText:@&quot;Touch to start&quot;];<br \/>\n[self titleLabel];<\/p>\n<p>\/\/ add the player prite<br \/>\nSKSpriteNode\u00a0*player\u00a0=\u00a0[SKSpriteNode spriteNodeWithImageNamed:@&quot;Bird&quot;];<br \/>\n[player setPosition:CGPointMake(self.size.width\/2, self.size.height\/2)];<br \/>\n[self addChild:player];[\/code]<\/p>\n<p>You should see something like this:<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-13.02.40.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3106\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-13.02.40.png?resize=434%2C704\" alt=\"Screenshot 2014-02-22 13.02.40\" width=\"434\" height=\"704\" \/><\/a><\/p>\n<h4>Making game scene<\/h4>\n<p>Make a new file, MyWorld.m of type Sprite.<br \/>\nNext in MyScene.h in touchesBegan method, replace contents with<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]-\u00a0(void)touchesBegan:(NSSet\u00a0*)touches withEvent:(UIEvent\u00a0*)event<br \/>\n{<br \/>\n  \/\/ choose you animation<br \/>\n  SKTransition\u00a0*transition\u00a0=\u00a0[SKTransition doorsCloseHorizontalWithDuration:.4];\/\/ present new scene<br \/>\n  MyWorld\u00a0*main\u00a0=\u00a0[[MyWorld alloc]\u00a0initWithSize:self.size];<br \/>\n  [self.scene.view presentScene:main transition:transition];<br \/>\n}[\/code]<\/p>\n<p>Now, in your new file, draw the layer like the main menu, as you want in the initWithSize method.<br \/>\nBefore drawing the elements, you need to apply the gravity on your world<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]\/\/ customize your gravity here<br \/>\n[self.physicsWorld setGravity:CGVectorMake(0,\u00a0-10)];\/\/ detect collision enabled<br \/>\n[self.physicsWorld setContactDelegate:self];[\/code]<\/p>\n<p>For this project I\u2019ve used an extension of SKSpriteNode, called PBParallaxScrolling. You can find it on github.<br \/>\nIt\u2019s an extension used to easily make parallax scrolling. Download and add.<\/p>\n<p>PBParallaxScrolling is used for example to scroll sky:<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]PBParallaxScrolling\u00a0*\u00a0parallax\u00a0=\u00a0[[PBParallaxScrolling alloc]<br \/>\n    initWithBackgrounds:@[@&quot;MarioBackground-scrolling-top&quot;]<br \/>\n    size:CGSizeMake(320, self.frame.size.height)\u00a0direction:kPBParallaxBackgroundDirectionLeft<br \/>\n    fastestSpeed:1.0<br \/>\n    andSpeedDecrease:kPBParallaxBackgroundDefaultSpeedDifferential];<\/p>\n<p>_parallaxBackgroundSky\u00a0=\u00a0parallax;<br \/>\n[self addChild:parallax];[\/code]<\/p>\n<p>or to scroll background:<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]PBParallaxScrolling\u00a0*\u00a0parallax\u00a0=\u00a0[[PBParallaxScrolling alloc]<br \/>\n    initWithBackgrounds:@[@&quot;MarioBackground-scrolling&quot;]<br \/>\n    size:CGSizeMake(320, self.view.frame.size.height\u00a0+\u00a070)\u00a0direction:kPBParallaxBackgroundDirectionLeft<br \/>\n    fastestSpeed:2.1<br \/>\n    andSpeedDecrease:kPBParallaxBackgroundDefaultSpeedDifferential];<\/p>\n<p>_parallaxBackground\u00a0=\u00a0parallax;<br \/>\n[self addChild:parallax];\/\/ 1<\/p>\n<p>_parallaxBackground.physicsBody\u00a0=\u00a0[SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(320,\u00a05)];<br \/>\n[_parallaxBackground.physicsBody setAffectedByGravity:NO];<br \/>\n[_parallaxBackground.physicsBody setDynamic:NO];<br \/>\n[_parallaxBackground.physicsBody setCategoryBitMask:0x3\u00a0];<br \/>\n[_parallaxBackground.physicsBody setCollisionBitMask:\u00a00x1];[\/code]<\/p>\n<p>the background layer, recognize collision and gravity.<br \/>\n1) we created the body to don\u2019t fall outside screen and to bounce on the floor.<\/p>\n<p>Also the player should recognize gravity and collision.<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]\/\/ APSpritePlayer is a SKSpriteNode class, empty.<br \/>\n_player\u00a0=\u00a0[APSpritePlayer spriteNodeWithImageNamed:@&quot;Bird&quot;];<br \/>\n[_player setPosition:CGPointMake(self.size.width\/2, self.size.height\/2)];<br \/>\n[self addChild:_player];_player.physicsBody\u00a0=\u00a0[SKPhysicsBody bodyWithRectangleOfSize:_player.size];<br \/>\n[_player.physicsBody setDensity:kDensity];<br \/>\n[_player.physicsBody setAllowsRotation:NO];<br \/>\n[_player.physicsBody setCategoryBitMask:0x1\u00a0];<br \/>\n\/\/ bitmask for collision groups<br \/>\n[_player.physicsBody setContactTestBitMask:0x2 | 0x3];<br \/>\n[_player.physicsBody setCollisionBitMask:0x3 | 0x2];[\/code]<\/p>\n<p>If it\u2019s all correct, you should see your fish that fall down on the screen and stop on the floor. Parallax backgrounds and sky are currently not updated.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo.gif\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3114\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo.gif?resize=264%2C480\" alt=\"Senza titolo\" width=\"264\" height=\"480\" \/><\/a><\/p>\n<h5>Make thing moving!<\/h5>\n<p>Add or edit, touchBegan and update methods to play with animations.<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]\/\/ jump on touch<br \/>\n&#8211;\u00a0(void)touchesBegan:(NSSet\u00a0*)touches withEvent:(UIEvent\u00a0*)event<br \/>\n{<br \/>\n    \/\/ make fish jump<br \/>\n    [_player.physicsBody setVelocity:CGVectorMake(_player.physicsBody.velocity.dx,\u00a0400)];<br \/>\n}<\/p>\n<p>\/\/ update loop method<br \/>\n&#8211;\u00a0(void)update:(NSTimeInterval)currentTime<br \/>\n{<br \/>\n    \/\/ scroll parallaxes<br \/>\n    [_parallaxBackground \u00a0 \u00a0update:currentTime];<br \/>\n    [_parallaxBackgroundSky update:currentTime];if\u00a0(_player.physicsBody.velocity.dy &amp;gt;\u00a0400)\u00a0{<br \/>\n    [_player.physicsBody setVelocity:CGVectorMake(_player.physicsBody.velocity.dx,\u00a0400)];<br \/>\n}<\/p>\n<p>\/\/ rotate player on jump \/ fall down<br \/>\nCGFloat rotation\u00a0=\u00a0((_player.physicsBody.velocity.dy\u00a0+\u00a0400)\u00a0\/\u00a0(2*400))\u00a0*\u00a0M_2_PI;<br \/>\n[_player setZRotation:rotation-M_1_PI\/2];[\/code]<\/p>\n<p>Well done, now you\u2019re able to jump!<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo-1.gif\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3117\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo-1.gif?resize=272%2C480\" alt=\"Senza titolo (1)\" width=\"272\" height=\"480\" \/><\/a><\/p>\n<h5>Add and count score<\/h5>\n<p>You\u2019re should be able to draw a label. Add a label on top-center of screen with text @\u201d0\u2033.<\/p>\n<p>In your initWithSize method, after all drawing, add a schedule, to update score.<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;][\u00a0NSTimer\u00a0scheduledTimerWithTimeInterval:1.5\u00a0target:self selector:@selector(startScoreTimer)\u00a0userInfo:nil\u00a0repeats:YES\u00a0];[\/code]<\/p>\n<p>This call every 1.5 seconds, startScoreTimer method and make a +1 on the score label.<br \/>\nSave 1.5 value! This must be the same time of the pipes creation interval!<\/p>\n<h5>Add the random pipes<\/h5>\n<p>First draw the pipes yourself!<br \/>\nPipes are SKSpriteNode objects. Place it on screen in a fixed distance one with one.<br \/>\nMake drawing in a method that you next schedule with\u00a0<strong>1.5<\/strong>\u00a0seconds of interval and drawing continuously.<\/p>\n<p>Every pipe should detect collision, of course!<br \/>\nLike the ground, we need to set to the pipe the physical body and gravity.<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]pipeTop.physicsBody\u00a0=\u00a0[SKPhysicsBody bodyWithRectangleOfSize:pipeTop.size];<br \/>\n[pipeTop.physicsBody setAffectedByGravity:NO];<br \/>\n[pipeTop.physicsBody setDynamic:NO];<br \/>\n[pipeTop.physicsBody setCategoryBitMask:\u00a00x2];<br \/>\n[pipeTop.physicsBody setCollisionBitMask:0x1];[\/code]<\/p>\n<p>Do the same things for the pipeDown that you will make.<\/p>\n<p>Move pipes:<\/p>\n<p>To make a continuous horizontal scolling, we use SKAction repeating forever the loop.<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]\/ Move top pipe<br \/>\nSKAction\u00a0*pipeTopAction\u00a0=\u00a0[SKAction moveToX:-(pipeTop.size.width\/2)\u00a0duration:1.5];<br \/>\nSKAction\u00a0*pipeTopSequence\u00a0=\u00a0[SKAction sequence:@[pipeTopAction,\u00a0[SKAction runBlock:^{<br \/>\n    [pipeTop removeFromParent];<br \/>\n}]]];<br \/>\n[pipeTop runAction:[SKAction repeatActionForever:pipeTopSequence]];[\/code]<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo-2.gif\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3120\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Senza-titolo-2.gif?resize=272%2C480\" alt=\"Senza titolo (2)\" width=\"272\" height=\"480\" \/><\/a><\/p>\n<h5>Collision detection<\/h5>\n<p>At the beginning we setted physics world collision delegate.<br \/>\nThis make didBeginContact being called on collision.<\/p>\n<p>And now we add this method!<\/p>\n<p>[code lang=&#8221;java&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]-\u00a0(void)didBeginContact:(SKPhysicsContact\u00a0*)contact<br \/>\n{<br \/>\n  SKNode\u00a0*node\u00a0=\u00a0contact.bodyA.node;\/\/ boom!<br \/>\n  if\u00a0([node isKindOfClass:[APSpritePlayer class]])<br \/>\n  {<br \/>\n    SKTransition\u00a0*transition\u00a0=\u00a0[SKTransition doorsCloseHorizontalWithDuration:.4];\/\/ go back to main menu<br \/>\n    APMainMenu\u00a0*newGame\u00a0=\u00a0[[APMainMenu alloc]\u00a0initWithSize:self.size];<br \/>\n    [self.scene.view presentScene:newGame transition:transition];<br \/>\n  }<br \/>\n}[\/code]<\/p>\n<p>Now you\u2019re able to detect collision, jump, move pipes, count score, move background and move sky!<br \/>\nThat\u2019s all.<\/p>\n<p>As usual, it\u2019s a starting point, and you can\u00a0<a href=\"http:\/\/www.albertopasca.it\/labs\/libs\/download.php?fname=Sprite_Test.zip\" target=\"_blank\" rel=\"noopener\">download here<\/a>.<br \/>\nYou can also improve, edit and make money using\u00a0<a href=\"https:\/\/github.com\/elpsk\" target=\"_blank\" rel=\"noopener\">github version<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As explained in the last post, (\u00a0How to make Flappy Bird like game using Cocos2D\u00a0) today, we learn how to make a Flappy Bird game using Objectivec SKSpriteKit for iOS7 in 20 rows of code!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[41,91,92,89,21,87,93,94,90],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-generic","tag-animation","tag-clone","tag-flappy","tag-flappy-bird","tag-game","tag-ios","tag-skspritekit","tag-skspritenode","tag-uikit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"As explained in the last post, (\u00a0How to make Flappy Bird like game using Cocos2D\u00a0) today, we learn how to make a Flappy Bird game using Objectivec SKSpriteKit for iOS7 in 20 rows of code!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-05T15:09:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-25T12:02:11+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"[Objc] How to make Flappy Bird like game using UIKit\",\"datePublished\":\"2014-02-05T15:09:44+00:00\",\"dateModified\":\"2018-05-25T12:02:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/\"},\"wordCount\":1179,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/Screenshot-2014-02-22-01.19.57.png\",\"keywords\":[\"animation\",\"clone\",\"flappy\",\"flappy bird\",\"game\",\"iOS\",\"skspritekit\",\"skspritenode\",\"uikit\"],\"articleSection\":[\"generic\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/\",\"name\":\"[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/Screenshot-2014-02-22-01.19.57.png\",\"datePublished\":\"2014-02-05T15:09:44+00:00\",\"dateModified\":\"2018-05-25T12:02:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/Screenshot-2014-02-22-01.19.57.png\",\"contentUrl\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/Screenshot-2014-02-22-01.19.57.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/how-to-make-flappy-bird-like-game-using-uikit\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Objc] How to make Flappy Bird like game using UIKit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/","og_locale":"en_US","og_type":"article","og_title":"[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}","og_description":"As explained in the last post, (\u00a0How to make Flappy Bird like game using Cocos2D\u00a0) today, we learn how to make a Flappy Bird game using Objectivec SKSpriteKit for iOS7 in 20 rows of code!","og_url":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2014-02-05T15:09:44+00:00","article_modified_time":"2018-05-25T12:02:11+00:00","og_image":[{"url":"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png","type":"","width":"","height":""}],"author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#article","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"[Objc] How to make Flappy Bird like game using UIKit","datePublished":"2014-02-05T15:09:44+00:00","dateModified":"2018-05-25T12:02:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/"},"wordCount":1179,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#primaryimage"},"thumbnailUrl":"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png","keywords":["animation","clone","flappy","flappy bird","game","iOS","skspritekit","skspritenode","uikit"],"articleSection":["generic"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/","url":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/","name":"[Objc] How to make Flappy Bird like game using UIKit - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#primaryimage"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#primaryimage"},"thumbnailUrl":"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png","datePublished":"2014-02-05T15:09:44+00:00","dateModified":"2018-05-25T12:02:11+00:00","breadcrumb":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#primaryimage","url":"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png","contentUrl":"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/02\/Screenshot-2014-02-22-01.19.57.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.albertopasca.it\/whiletrue\/how-to-make-flappy-bird-like-game-using-uikit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"[Objc] How to make Flappy Bird like game using UIKit"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":14,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":787,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/233\/revisions\/787"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}