SlideShare a Scribd company logo
1 of 70
Download to read offline
iOS Game Development
                            with Cocos2D




                                    Yaron Karasik
                        yaronkarasik@gmail.com @Greenwell
Thursday, June 21, 12
iOS Game Development
                                 with Cocos2D


                        Part 1: Why Cocos2D?
                        Part 2: Cocos2D Basics
                        Part 3: Let’s build a Cocos2D game



Thursday, June 21, 12
Part 1:
                        Why Cocos2D?




Thursday, June 21, 12
Meet Cocos2D for iPhone
           ★     Open source iOS game development framework
           ★     Developed by Ricardo Quesada, acqui-hired by
                 Zynga (2011)
           ★     Stable v1.1 Based on OpenGL ES 1.1
           ★     Beta v2.0 Based on OpenGL ES 2.0
           ★     3,500+ iOS games shipped




Thursday, June 21, 12
The Cocos2D Family


                                                                                   Cocos3D
                                                                                   (Obj-C)

            Cocos2d-Android
                 (Java)
                                                                    Cocos2d-Mac
                                              Cocos2d-X               (Obj-C)
                                         iPhone/Android (C++)




                     Cocos2d-XNA                                Cocos2d-HTML5
                  Windows Phone 7 (C#)                          Web (Javascript)



Thursday, June 21, 12
Proven Success




Thursday, June 21, 12
Great Effort-Flexibility Balance

                                                 Direct OpenGL/
                   100                            CoreGraphics
          Effort




                                                          Cocos2D/Sparrow

                             Unity/Corona
                        0
                                            Flexibility



Thursday, June 21, 12
Cross Device, Cross Resolution




Thursday, June 21, 12
Active Ecosystem




Thursday, June 21, 12
And most importantly..
                           Tons of great features for games

                          Sprite Sheets             Scene Transitions           Parallax Scrolling



                               Effects:                                           Actions:
                                                    Tile Map Support
                        Lense, Ripple, Wave..                                Move, Rotate, Scale..



                        Particle Systems        Integrated Physics Engines       Text Rendering



                            Ribbons                  Shaders (v2.0)              Sound Support




Thursday, June 21, 12
Part 2:
                        Cocos2D Basics




Thursday, June 21, 12
Basic Cocos2D Concepts
                                Director




Thursday, June 21, 12
Basic Cocos2D Concepts
                                Director



                                 Scenes




Thursday, June 21, 12
Basic Cocos2D Concepts
                                Director



                                 Scenes




                                 Layers




Thursday, June 21, 12
Basic Cocos2D Concepts
                                Director



                                 Scenes




                                 Layers


                                 Sprites



Thursday, June 21, 12
Director & Scenes
                    Director                   Loss


                  Intro         Main Menu     Level I     Level 2      Victory


                                             Options


                                            High Scores


                  ★     Game made up of “game screens” called Scenes
                  ★     Each Scene can be considered a separate app
                  ★     Director handles main window and executes Scenes

Thursday, June 21, 12
Layers




                ★       Each Scene contains several full screen Layers
                ★       Layers contain Sprites which are the game elements
                ★       Layers useful for Controls, Background, Labels, Menus.

Thursday, June 21, 12
Nodes


                        Nodes are anything that gets drawn or contains
                        things that get drawn (= Scene, Layer, Sprite)
                        Can:   ★   Contain other Nodes
                               ★   Schedule periodic callbacks
                               ★   Execute Actions




Thursday, June 21, 12
Sprites in Action

                                                                  Create




                  CCSpriteFrame* spriteFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
                                                        spriteFrameByName:@"sprite.png"];

                  CCSprite* sprite = [CCSprite spriteWithSpriteFrame:spriteFrame];




Thursday, June 21, 12
Sprites in Action
               winSize.height


                                                          Add to Layer


                                                (x,y) at anchor point




                                                                         winSize.width
                   (0,0)
                                sprite.position = ccp(x, y);

                                [layer addChild:sprite z:5 tag:666];




Thursday, June 21, 12
Sprites in Action

                                                                       Move




                        CCMoveTo *moveToAction = [CCMoveTo actionWithDuration:duration
                                                                     position:newPosition];

                        [sprite runAction:moveToAction];


                Properties can be transformed directly or through actions
Thursday, June 21, 12
Sprites in Action

                                                          Scale/Rotate




          CCScaleTo *scaleToAction = [CCScaleTo actionWithDuration:duration scale:scale];
          CCRotateBy *rotateByAction = [CCRotateBy actionWithDuration:duration angle:angle];

          CCSequence *sequence = [CCSequence actions:scaleToAction, rotateByAction, nil];

          [sprite runAction:sequence];



Thursday, June 21, 12
Sprites in Action

                                                                   Animate




                        CCAnimation* animation = [[CCAnimationCache sharedAnimationCache]
                                                               animationByName:@"animation"];
                        CCAnimate* animateAction = [CCAnimate actionWithAnimation:animation];

                        [sprite runAction:animateAction];




Thursday, June 21, 12
Sprites in Action

                                                       Schedule Updates




                        [scene schedule:@selector(updateSprite:) interval:interval];




Thursday, June 21, 12
Actions
                           Can be performed on Sprites or any Node


                        Basic       Move, Scale, Rotate, Bezier, Hide, Fade, Tint..

                  Composition        Sequence, Repeat, Spawn, RepeatForever..

                         Ease           Ease, EaseExponential, EaseBounce..

                        Effects       Lens, Liquid, Ripple, Shaky, Twirl, Waves..

                        Special                   CallFunc, Follow..



Thursday, June 21, 12
Spritesheets




                        ★   Added as a child to the layer
                        ★   Created with TexturePacker or Zwoptex
                        ★   Memory considerations, 16bit images, .pvr.ccz

Thursday, June 21, 12
Controls

                    - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

                    - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

                    - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

                    - (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;




             ★     Implement directly based on CCStandardTouchDelegate
             ★     Can use UIGestureRecognizer classes
             ★     Open source implementations of joypad/buttons available




Thursday, June 21, 12
Part 3:
                        Let’s Make a Game!


Thursday, June 21, 12
Part 3:
                        Let’s Make a Game!
                        ..but first we need a story, graphics, music and sfx :)




Thursday, June 21, 12
Para-Shoot


                        Because he likes to kill paratroopers




Thursday, June 21, 12
Graphics




                        Benjamin Radchek Sprites by The_Protoganist and _Allen_
                              http://www.freewebs.com/teh_pro/sprites.htm

Thursday, June 21, 12
Music & SFX




                        Background music, shoot sound, death sound




                               Explosive Attack by McTricky @ Sakari Infinity
                               http://www.sakari-infinity.net/author/McTricky

Thursday, June 21, 12
Music & SFX




                        Background music, shoot sound, death sound




                               Explosive Attack by McTricky @ Sakari Infinity
                               http://www.sakari-infinity.net/author/McTricky

Thursday, June 21, 12
Sneak Peek


Thursday, June 21, 12
Steps for making Para-Shoot
                        Application Setup
                        Step 1: Adding Background
                        Step 2: Adding Our Hero
                        Step 3: Adding Bad Guys (Game Logic)
                        Step 4: Killing Bad Guys (Adding UI)
                        Step 5: Check for Bad Guy Death
                        Step 6: Animating Our Hero
                        Step 7: Animating Bad Guys Dying
                        Step 8: Adding Body Count
                        Step 9: Adding Sound & Music

Thursday, June 21, 12
New Cocos2D Project




Thursday, June 21, 12
HelloWorldScene.h
                        @interface HelloWorldLayer : CCLayer
                        {
                        ! // Player sprite
                        ! CCSprite *_player;

                            // Target and bullet sprite arrays
                        !   NSMutableArray *_targets;
                            NSMutableArray *_bullets;

                        !   // Body count counter and isShooting flag
                            int _bodyCount;
                            BOOL _isShooting;
                        !
                        !   // For body count label
                        !   CCLabelTTF *_labelTitle;
                        !   CCLabelTTF *_labelCount;
                        }




Thursday, June 21, 12
HelloWorldScene.m

                        // Create the new scene including this layer
                        +(id) scene
                        {
                        ! // Create the scene
                        ! CCScene *scene = [CCScene node];
                        !
                        ! // Create the layer
                        ! HelloWorldLayer *layer = [HelloWorldLayer node];
                        !
                        ! // add layer as a child to scene
                        ! [scene addChild: layer];
                        !
                        ! // return the scene
                        ! return scene;
                        }




Thursday, June 21, 12
Hello World




Thursday, June 21, 12
Step 1: Adding Background


        (In init)

        // Get the window size to place elements
        CGSize winSize = [[CCDirector sharedDirector] winSize];

        // Add the background image
        CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
        background.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:background z:0];




Thursday, June 21, 12
Step 1: Adding Background




Thursday, June 21, 12
Step 2: Adding Our Hero
                                      Preload the spritesheet




                 (In init)
                 // Load the sprite sheet
                 CCSpriteBatchNode *batchNode = [CCSpriteBatchNode
                                    batchNodeWithFile:@"parashoot.pvr.ccz"];
                 [self addChild:batchNode];

                 // Load the sprites into the shareSpriteFrameCache
                 [[CCSpriteFrameCache sharedSpriteFrameCache]
                                addSpriteFramesWithFile:@"parashoot.plist"];




Thursday, June 21, 12
Step 2: Adding Our Hero
                                        Add the hero sprite



               // Add the player sprite
               CCSpriteFrame* playerFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
               spriteFrameByName:@"player_01.png"];

               _player = [CCSprite spriteWithSpriteFrame:playerFrame];
               _player.position = ccp(_player.contentSize.width/2 + 10, winSize.height/2);

               [self addChild:_player z:1];




Thursday, June 21, 12
Step 2: Adding Our Hero




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)
                          Schedule a new target every second




              (in init)

              [self schedule:@selector(addTarget:) interval:1.0f];




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)
                                  Create a sprite for the target




          // Create a new enemy
          -(void)addTarget:(ccTime)dt {

                // Create the target sprite
               CCSpriteFrame *targetFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
                                                        spriteFrameByName:@"target.png"];
               !CCSprite *target = [CCSprite spriteWithSpriteFrame:targetFrame];

                 // Add the target to the layer and the array
          !      [self addChild:target];
          !      [_targets addObject:target];




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)
                             Generate a random x position for the target


              !         // Determine where to spawn the target along the X axis
              !         CGSize winSize = [[CCDirector sharedDirector] winSize];

                        // Find a random X for the target in the right half of the screen
              !         int minX = winSize.width/2;
              !         int maxX = winSize.width - target.contentSize.width;
              !         int rangeX = maxX - minX;
              !         int actualX = (arc4random() % rangeX) + minX;
                        target.position = ccp(actualX, 320);
                        target.anchorPoint = ccp(0, 0);

              !         // Determine speed of the target
              !         int minDuration = 2.0;
              !         int maxDuration = 4.0;
              !         int rangeDuration = maxDuration - minDuration;
              !         int actualDuration = (arc4random() % rangeDuration) + minDuration;




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)
                        Create a move action for the target with a
                           callback when reaching the bottom


      // Create and run the actions
      CCMoveTo* moveTarget = [CCMoveTo actionWithDuration:actualDuration
                    ! ! ! position:ccp(actualX, -target.contentSize.height/2)];
      CCCallFuncN* actionForTargetMoveDidFinish = [CCCallFuncN
                   actionWithTarget:self selector:@selector(targetMoveFinished:)];

      [target runAction:[CCSequence actions:moveTarget, actionForTargetMoveDidFinish, nil]];




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)
                        Add the callback method for a target that
                              dies or reaches the bottom

              // Method for removing a target that has died or reached the
              bottom

              -(void)targetMoveFinished:(id)sender {
              ! CCSprite *target = (CCSprite *)sender;
                 [self removeChild:target cleanup:YES];
              ! [_targets removeObject:target];
              }




Thursday, June 21, 12
Step 3: Adding Bad Guys (Game Logic)




Thursday, June 21, 12
Step 4: Killing Bad Guys (Adding UI)
                                             Detect the touch




               - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
               !   // Choose one of the touches to work with
               !   UITouch *touch = [touches anyObject];
               !   CGPoint location = [touch locationInView:[touch view]];
               !   location = [[CCDirector sharedDirector] convertToGL:location];
               !
                   if (!_isShooting) {
                       _isShooting = YES;




Thursday, June 21, 12
Step 4: Killing Bad Guys (Adding UI)
                                             Create the bullet

               // Create the bullet
               CCSpriteFrame* bulletFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
                                                         spriteFrameByName:@"bullet.png"];
               CCSprite* bulletSprite = [CCSprite spriteWithSpriteFrame:bulletFrame];
               bulletSprite.position = _player.position;

               // Bullet actions
               CCCallFuncN* actionForRemoveBullet = [CCCallFuncN actionWithTarget:self
                                                      selector:@selector(removeBullet:)];
               CCMoveBy* bulletMoveBy = [CCMoveBy actionWithDuration:1.0f
                                                            position:ccp(winSize.width, 0)];
               [bulletSprite runAction:[CCSequence actionOne:bulletMoveBy
                                                         two:actionForRemoveBullet]];

               // Add bullet to layer and array
               [self addChild:bulletSprite];
               [_bullets addObject:bulletSprite];




Thursday, June 21, 12
Step 4: Killing Bad Guys (Adding UI)




Thursday, June 21, 12
Step 5: Check for Bad Guy Death

               -(void)update:(ccTime)dt {
                   CCSprite* bulletToRemove = nil;

                        for (CCSprite *bullet in _bullets) {
                            for (CCSprite* target in _targets) {
                                CGRect targetBox = CGRectMake(target.position.x, target.position.y,
                                      [target boundingBox].size.width, [target boundingBox].size.height);

                                // Check if bullet is in the target's bounding box
                                if (CGRectContainsPoint(targetBox, bullet.position)) {

                                // Animate target death and remove target

                                    bulletToRemove = bullet;
                                }
                            }
                        }

                        // Remove bullet if target was hit
                        if (bulletToRemove != nil) {
                            [self removeChild:bulletToRemove cleanup:YES];
                            [_bullets removeObject:bulletToRemove];
                        }
               }




Thursday, June 21, 12
Step 5: Check for Bad Guy Death




Thursday, June 21, 12
Step 6: Animating Our Hero
                        Preload the animation from the spritesheet



           (In init)

           // Load the animation for player
           NSMutableArray *animFrames1 = [NSMutableArray array];
           for (int i = 1; i < 12; i++) {
               CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
                                                    [NSString stringWithFormat:@"player_%02d.png",i]];
           !   [animFrames1 addObject:frame];
           }

           [[CCAnimationCache sharedAnimationCache] addAnimation:[CCAnimation
                             animationWithFrames:animFrames1 delay:FRAME_DELAY] name:@"player"];!




Thursday, June 21, 12
Step 6: Animating Our Hero
                                Animate the hero when shooting



          (In ccTouchesEnded)

          // Actions for shooting animation
          CCCallFunc* actionForShootDidEnd = [CCCallFunc actionWithTarget:self
                                                          selector:@selector(shootDidEnd)];

          CCAnimation* playerShootAnimation = [[CCAnimationCache sharedAnimationCache]
                                                                animationByName:@"player"];
          CCAnimate* shootAnimate = [CCAnimate actionWithAnimation:playerShootAnimation];

          [_player runAction:[CCSequence actionOne:shootAnimate two:actionForShootDidEnd]];




Thursday, June 21, 12
Step 6: Animating Our Hero




Thursday, June 21, 12
Step 7: Animating Bad Guys Dying



           (in update)

           // Set up actions for animation and target removal
           CCCallFuncN* actionForDeathDidFinish = [CCCallFuncN actionWithTarget:self
                                                             selector:@selector(targetMoveFinished:)];

           CCAnimate* deathAnimation = [CCAnimate actionWithAnimation:[[CCAnimationCache
                            sharedAnimationCache] animationByName:@"death"] restoreOriginalFrame:NO];

           [target runAction:[CCSequence actionOne:deathAnimation two:actionForDeathDidFinish]];




Thursday, June 21, 12
Step 7: Animating Bad Guys Dying




Thursday, June 21, 12
Step 8: Adding Body Count


            (In init)

            NSString* bodyCountString = [NSString stringWithFormat:@"%d", _bodyCount];
            _labelCount = [CCLabelTTF labelWithString:bodyCountString fontName:@"Arial"
                                                                      fontSize:16];
            _labelCount.color = ccc3(0,0,0);
            _labelCount.position = ccp(110, winSize.height - 16);
            [self addChild:_labelCount z:2];

            (In ccTouchesEnded)

            _bodyCount++;
            NSString* bodyCountString = [NSString stringWithFormat:@"%d", _bodyCount];!
            [_labelCount setString:bodyCountString];




Thursday, June 21, 12
Step 8: Adding Body Count




Thursday, June 21, 12
Step 9: Adding Sound & Music


          (In init)

          ! // Start background music, set lower volume

          ! SimpleAudioEngine.sharedEngine.backgroundMusicVolume = 0.4f;
          ! [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"explosive_attack.mp3"];

          (In ccTouchesEnded)

          ! // Play sound effect on every shot and on death

          ! [[SimpleAudioEngine sharedEngine] playEffect:@"shot.wav"];
          ! [[SimpleAudioEngine sharedEngine] playEffect:@"death.wav"];




Thursday, June 21, 12
Step 9: Adding Sound & Music




Thursday, June 21, 12
Let’s Play!


Thursday, June 21, 12
Para-Shoot 2.0

                        Enemies can move and attack
                        Joypad + HUD
                        Move our hero
                        Different weapons, power ups and health
                        Game menu and high scores
                        Levels
                        Save/Load Game
                        Refactor code (More scenes and layers)


Thursday, June 21, 12
Refactoring Para-Shoot

                  Scenes:                                           Loss


                              Intro         Main Menu             Level X             Victory


                                                                  Options


                                                                 High Score



                  Layers:
                        Level X       Background        Player             Bad Guys     Joypad/HUD




Thursday, June 21, 12
More stuff to explore


                        ★   Physics Engines - Chipmunk and Box2D
                        ★   Particle System
                        ★   Tilemaps
                        ★   Menu Interface




Thursday, June 21, 12
Where can you learn more

                        Cocos2D Demo Library (Comes with Cocos)

                             Wiki: http://cocos2d-iphone.org/wiki

                        Ray Wenderlich: http://www.raywenderlich.com

                          Steffen Itterheim: http://learn-cocos2d.com

        Sapus Tongue Source Code: http://www.sapusmedia.com/sources




Thursday, June 21, 12
Thank You!
                            Yaron Karasik
                        yaronkarasik@gmail.com
                             @Greenwell




Thursday, June 21, 12

More Related Content

Viewers also liked

Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x EngineDuy Tan Geek
 
Mobile Game Development in Unity
Mobile Game Development in UnityMobile Game Development in Unity
Mobile Game Development in UnityHakan Saglam
 
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장VentureSquare
 
Howtoよいデザイン
HowtoよいデザインHowtoよいデザイン
HowtoよいデザインHiroki Yagita
 
Social definitions
Social definitionsSocial definitions
Social definitionsBrandt
 
5.Apostoł narodów
5.Apostoł narodów5.Apostoł narodów
5.Apostoł narodówparakletos
 
12.Od wędrownych misjonarzy do lokalnej wspólnoty
12.Od wędrownych misjonarzy do lokalnej wspólnoty12.Od wędrownych misjonarzy do lokalnej wspólnoty
12.Od wędrownych misjonarzy do lokalnej wspólnotyparakletos
 
Ocv nola may2012_final-pdf
Ocv nola may2012_final-pdfOcv nola may2012_final-pdf
Ocv nola may2012_final-pdfCharles Figley
 
Indiana Unviversity School of Medicine Computer ID Brochure Page 1
Indiana Unviversity School of Medicine Computer ID Brochure Page 1Indiana Unviversity School of Medicine Computer ID Brochure Page 1
Indiana Unviversity School of Medicine Computer ID Brochure Page 1mmorone
 
Legal and ethical issues
Legal and ethical issuesLegal and ethical issues
Legal and ethical issueslisadevine21
 
Ayurveda swadeshi chikitsa- part 1 by rajiv dixit
Ayurveda swadeshi chikitsa- part 1 by rajiv dixitAyurveda swadeshi chikitsa- part 1 by rajiv dixit
Ayurveda swadeshi chikitsa- part 1 by rajiv dixitBhim Upadhyaya
 
Dynamic covered call writing June 2013 - Eden Rahim
Dynamic covered call writing June 2013 - Eden RahimDynamic covered call writing June 2013 - Eden Rahim
Dynamic covered call writing June 2013 - Eden Rahimsorenk
 
8.Droga kościoła do samodzielności
8.Droga kościoła do samodzielności8.Droga kościoła do samodzielności
8.Droga kościoła do samodzielnościparakletos
 
Ilzenes pagasts_MD
Ilzenes pagasts_MDIlzenes pagasts_MD
Ilzenes pagasts_MDilzenesbibl
 
75 idea to rock your socks
75 idea to rock your socks 75 idea to rock your socks
75 idea to rock your socks Barbara Savona
 
Chinwa_Profile_final_v5
Chinwa_Profile_final_v5Chinwa_Profile_final_v5
Chinwa_Profile_final_v5xhaytham
 

Viewers also liked (20)

Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
 
Mobile Game Development in Unity
Mobile Game Development in UnityMobile Game Development in Unity
Mobile Game Development in Unity
 
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장
16회 오픈업/우리 게임은 어디에 출시할까?_MS오성미부장
 
Mobile Application Development Process
Mobile Application Development ProcessMobile Application Development Process
Mobile Application Development Process
 
Howtoよいデザイン
HowtoよいデザインHowtoよいデザイン
Howtoよいデザイン
 
Social definitions
Social definitionsSocial definitions
Social definitions
 
5.Apostoł narodów
5.Apostoł narodów5.Apostoł narodów
5.Apostoł narodów
 
12.Od wędrownych misjonarzy do lokalnej wspólnoty
12.Od wędrownych misjonarzy do lokalnej wspólnoty12.Od wędrownych misjonarzy do lokalnej wspólnoty
12.Od wędrownych misjonarzy do lokalnej wspólnoty
 
Ocv nola may2012_final-pdf
Ocv nola may2012_final-pdfOcv nola may2012_final-pdf
Ocv nola may2012_final-pdf
 
Ica patient forum in atlanta 2009
Ica patient forum in atlanta   2009Ica patient forum in atlanta   2009
Ica patient forum in atlanta 2009
 
Indiana Unviversity School of Medicine Computer ID Brochure Page 1
Indiana Unviversity School of Medicine Computer ID Brochure Page 1Indiana Unviversity School of Medicine Computer ID Brochure Page 1
Indiana Unviversity School of Medicine Computer ID Brochure Page 1
 
Legal and ethical issues
Legal and ethical issuesLegal and ethical issues
Legal and ethical issues
 
Ayurveda swadeshi chikitsa- part 1 by rajiv dixit
Ayurveda swadeshi chikitsa- part 1 by rajiv dixitAyurveda swadeshi chikitsa- part 1 by rajiv dixit
Ayurveda swadeshi chikitsa- part 1 by rajiv dixit
 
Dynamic covered call writing June 2013 - Eden Rahim
Dynamic covered call writing June 2013 - Eden RahimDynamic covered call writing June 2013 - Eden Rahim
Dynamic covered call writing June 2013 - Eden Rahim
 
8.Droga kościoła do samodzielności
8.Droga kościoła do samodzielności8.Droga kościoła do samodzielności
8.Droga kościoła do samodzielności
 
Ilzenes pagasts_MD
Ilzenes pagasts_MDIlzenes pagasts_MD
Ilzenes pagasts_MD
 
75 idea to rock your socks
75 idea to rock your socks 75 idea to rock your socks
75 idea to rock your socks
 
Chinwa_Profile_final_v5
Chinwa_Profile_final_v5Chinwa_Profile_final_v5
Chinwa_Profile_final_v5
 
2.Judasz
2.Judasz2.Judasz
2.Judasz
 
Passie voor Oranje
Passie voor OranjePassie voor Oranje
Passie voor Oranje
 

Similar to iOS Game Development with Cocos2D

Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
Android game engine
Android game engineAndroid game engine
Android game engineJulian Chu
 
2 d gameplaytutorial
2 d gameplaytutorial2 d gameplaytutorial
2 d gameplaytutorialunityshare
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxGameLandVN
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...ogdc
 
06 html5 and cocos2d-x
06   html5 and cocos2d-x06   html5 and cocos2d-x
06 html5 and cocos2d-x乐费 胡
 
Under Cocos 2 D Tree_mdevcon 2013
Under Cocos 2 D Tree_mdevcon 2013Under Cocos 2 D Tree_mdevcon 2013
Under Cocos 2 D Tree_mdevcon 2013Wooga
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Maxim Zaks
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutesTroy Miles
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Troy Miles
 
The Battle Of Evate Report
The Battle Of Evate ReportThe Battle Of Evate Report
The Battle Of Evate ReportHuy Trần
 
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...Mathias Seguy
 
Creating physics game in 1 hour
Creating physics game in 1 hourCreating physics game in 1 hour
Creating physics game in 1 hourLinkou Bian
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdxGabriel Grill
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android GamesPlatty Soft
 

Similar to iOS Game Development with Cocos2D (20)

Basics cocos2d
Basics cocos2dBasics cocos2d
Basics cocos2d
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
Android game engine
Android game engineAndroid game engine
Android game engine
 
Programmers guide
Programmers guideProgrammers guide
Programmers guide
 
2 d gameplaytutorial
2 d gameplaytutorial2 d gameplaytutorial
2 d gameplaytutorial
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
 
06 html5 and cocos2d-x
06   html5 and cocos2d-x06   html5 and cocos2d-x
06 html5 and cocos2d-x
 
Under Cocos 2 D Tree_mdevcon 2013
Under Cocos 2 D Tree_mdevcon 2013Under Cocos 2 D Tree_mdevcon 2013
Under Cocos 2 D Tree_mdevcon 2013
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
Cocos2d game programming 2
Cocos2d game programming 2Cocos2d game programming 2
Cocos2d game programming 2
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 
The Battle Of Evate Report
The Battle Of Evate ReportThe Battle Of Evate Report
The Battle Of Evate Report
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...
Eclispe daytoulouse combining the power of eclipse with android_fr_1024_768_s...
 
Creating physics game in 1 hour
Creating physics game in 1 hourCreating physics game in 1 hour
Creating physics game in 1 hour
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdx
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

iOS Game Development with Cocos2D

  • 1. iOS Game Development with Cocos2D Yaron Karasik yaronkarasik@gmail.com @Greenwell Thursday, June 21, 12
  • 2. iOS Game Development with Cocos2D Part 1: Why Cocos2D? Part 2: Cocos2D Basics Part 3: Let’s build a Cocos2D game Thursday, June 21, 12
  • 3. Part 1: Why Cocos2D? Thursday, June 21, 12
  • 4. Meet Cocos2D for iPhone ★ Open source iOS game development framework ★ Developed by Ricardo Quesada, acqui-hired by Zynga (2011) ★ Stable v1.1 Based on OpenGL ES 1.1 ★ Beta v2.0 Based on OpenGL ES 2.0 ★ 3,500+ iOS games shipped Thursday, June 21, 12
  • 5. The Cocos2D Family Cocos3D (Obj-C) Cocos2d-Android (Java) Cocos2d-Mac Cocos2d-X (Obj-C) iPhone/Android (C++) Cocos2d-XNA Cocos2d-HTML5 Windows Phone 7 (C#) Web (Javascript) Thursday, June 21, 12
  • 7. Great Effort-Flexibility Balance Direct OpenGL/ 100 CoreGraphics Effort Cocos2D/Sparrow Unity/Corona 0 Flexibility Thursday, June 21, 12
  • 8. Cross Device, Cross Resolution Thursday, June 21, 12
  • 10. And most importantly.. Tons of great features for games Sprite Sheets Scene Transitions Parallax Scrolling Effects: Actions: Tile Map Support Lense, Ripple, Wave.. Move, Rotate, Scale.. Particle Systems Integrated Physics Engines Text Rendering Ribbons Shaders (v2.0) Sound Support Thursday, June 21, 12
  • 11. Part 2: Cocos2D Basics Thursday, June 21, 12
  • 12. Basic Cocos2D Concepts Director Thursday, June 21, 12
  • 13. Basic Cocos2D Concepts Director Scenes Thursday, June 21, 12
  • 14. Basic Cocos2D Concepts Director Scenes Layers Thursday, June 21, 12
  • 15. Basic Cocos2D Concepts Director Scenes Layers Sprites Thursday, June 21, 12
  • 16. Director & Scenes Director Loss Intro Main Menu Level I Level 2 Victory Options High Scores ★ Game made up of “game screens” called Scenes ★ Each Scene can be considered a separate app ★ Director handles main window and executes Scenes Thursday, June 21, 12
  • 17. Layers ★ Each Scene contains several full screen Layers ★ Layers contain Sprites which are the game elements ★ Layers useful for Controls, Background, Labels, Menus. Thursday, June 21, 12
  • 18. Nodes Nodes are anything that gets drawn or contains things that get drawn (= Scene, Layer, Sprite) Can: ★ Contain other Nodes ★ Schedule periodic callbacks ★ Execute Actions Thursday, June 21, 12
  • 19. Sprites in Action Create CCSpriteFrame* spriteFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"sprite.png"]; CCSprite* sprite = [CCSprite spriteWithSpriteFrame:spriteFrame]; Thursday, June 21, 12
  • 20. Sprites in Action winSize.height Add to Layer (x,y) at anchor point winSize.width (0,0) sprite.position = ccp(x, y); [layer addChild:sprite z:5 tag:666]; Thursday, June 21, 12
  • 21. Sprites in Action Move CCMoveTo *moveToAction = [CCMoveTo actionWithDuration:duration position:newPosition]; [sprite runAction:moveToAction]; Properties can be transformed directly or through actions Thursday, June 21, 12
  • 22. Sprites in Action Scale/Rotate CCScaleTo *scaleToAction = [CCScaleTo actionWithDuration:duration scale:scale]; CCRotateBy *rotateByAction = [CCRotateBy actionWithDuration:duration angle:angle]; CCSequence *sequence = [CCSequence actions:scaleToAction, rotateByAction, nil]; [sprite runAction:sequence]; Thursday, June 21, 12
  • 23. Sprites in Action Animate CCAnimation* animation = [[CCAnimationCache sharedAnimationCache] animationByName:@"animation"]; CCAnimate* animateAction = [CCAnimate actionWithAnimation:animation]; [sprite runAction:animateAction]; Thursday, June 21, 12
  • 24. Sprites in Action Schedule Updates [scene schedule:@selector(updateSprite:) interval:interval]; Thursday, June 21, 12
  • 25. Actions Can be performed on Sprites or any Node Basic Move, Scale, Rotate, Bezier, Hide, Fade, Tint.. Composition Sequence, Repeat, Spawn, RepeatForever.. Ease Ease, EaseExponential, EaseBounce.. Effects Lens, Liquid, Ripple, Shaky, Twirl, Waves.. Special CallFunc, Follow.. Thursday, June 21, 12
  • 26. Spritesheets ★ Added as a child to the layer ★ Created with TexturePacker or Zwoptex ★ Memory considerations, 16bit images, .pvr.ccz Thursday, June 21, 12
  • 27. Controls - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; ★ Implement directly based on CCStandardTouchDelegate ★ Can use UIGestureRecognizer classes ★ Open source implementations of joypad/buttons available Thursday, June 21, 12
  • 28. Part 3: Let’s Make a Game! Thursday, June 21, 12
  • 29. Part 3: Let’s Make a Game! ..but first we need a story, graphics, music and sfx :) Thursday, June 21, 12
  • 30. Para-Shoot Because he likes to kill paratroopers Thursday, June 21, 12
  • 31. Graphics Benjamin Radchek Sprites by The_Protoganist and _Allen_ http://www.freewebs.com/teh_pro/sprites.htm Thursday, June 21, 12
  • 32. Music & SFX Background music, shoot sound, death sound Explosive Attack by McTricky @ Sakari Infinity http://www.sakari-infinity.net/author/McTricky Thursday, June 21, 12
  • 33. Music & SFX Background music, shoot sound, death sound Explosive Attack by McTricky @ Sakari Infinity http://www.sakari-infinity.net/author/McTricky Thursday, June 21, 12
  • 35. Steps for making Para-Shoot Application Setup Step 1: Adding Background Step 2: Adding Our Hero Step 3: Adding Bad Guys (Game Logic) Step 4: Killing Bad Guys (Adding UI) Step 5: Check for Bad Guy Death Step 6: Animating Our Hero Step 7: Animating Bad Guys Dying Step 8: Adding Body Count Step 9: Adding Sound & Music Thursday, June 21, 12
  • 37. HelloWorldScene.h @interface HelloWorldLayer : CCLayer { ! // Player sprite ! CCSprite *_player; // Target and bullet sprite arrays ! NSMutableArray *_targets; NSMutableArray *_bullets; ! // Body count counter and isShooting flag int _bodyCount; BOOL _isShooting; ! ! // For body count label ! CCLabelTTF *_labelTitle; ! CCLabelTTF *_labelCount; } Thursday, June 21, 12
  • 38. HelloWorldScene.m // Create the new scene including this layer +(id) scene { ! // Create the scene ! CCScene *scene = [CCScene node]; ! ! // Create the layer ! HelloWorldLayer *layer = [HelloWorldLayer node]; ! ! // add layer as a child to scene ! [scene addChild: layer]; ! ! // return the scene ! return scene; } Thursday, June 21, 12
  • 40. Step 1: Adding Background (In init) // Get the window size to place elements CGSize winSize = [[CCDirector sharedDirector] winSize]; // Add the background image CCSprite *background = [CCSprite spriteWithFile:@"background.png"]; background.position = ccp(winSize.width/2, winSize.height/2); [self addChild:background z:0]; Thursday, June 21, 12
  • 41. Step 1: Adding Background Thursday, June 21, 12
  • 42. Step 2: Adding Our Hero Preload the spritesheet (In init) // Load the sprite sheet CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"parashoot.pvr.ccz"]; [self addChild:batchNode]; // Load the sprites into the shareSpriteFrameCache [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"parashoot.plist"]; Thursday, June 21, 12
  • 43. Step 2: Adding Our Hero Add the hero sprite // Add the player sprite CCSpriteFrame* playerFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"player_01.png"]; _player = [CCSprite spriteWithSpriteFrame:playerFrame]; _player.position = ccp(_player.contentSize.width/2 + 10, winSize.height/2); [self addChild:_player z:1]; Thursday, June 21, 12
  • 44. Step 2: Adding Our Hero Thursday, June 21, 12
  • 45. Step 3: Adding Bad Guys (Game Logic) Schedule a new target every second (in init) [self schedule:@selector(addTarget:) interval:1.0f]; Thursday, June 21, 12
  • 46. Step 3: Adding Bad Guys (Game Logic) Create a sprite for the target // Create a new enemy -(void)addTarget:(ccTime)dt { // Create the target sprite CCSpriteFrame *targetFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"target.png"]; !CCSprite *target = [CCSprite spriteWithSpriteFrame:targetFrame]; // Add the target to the layer and the array ! [self addChild:target]; ! [_targets addObject:target]; Thursday, June 21, 12
  • 47. Step 3: Adding Bad Guys (Game Logic) Generate a random x position for the target ! // Determine where to spawn the target along the X axis ! CGSize winSize = [[CCDirector sharedDirector] winSize]; // Find a random X for the target in the right half of the screen ! int minX = winSize.width/2; ! int maxX = winSize.width - target.contentSize.width; ! int rangeX = maxX - minX; ! int actualX = (arc4random() % rangeX) + minX; target.position = ccp(actualX, 320); target.anchorPoint = ccp(0, 0); ! // Determine speed of the target ! int minDuration = 2.0; ! int maxDuration = 4.0; ! int rangeDuration = maxDuration - minDuration; ! int actualDuration = (arc4random() % rangeDuration) + minDuration; Thursday, June 21, 12
  • 48. Step 3: Adding Bad Guys (Game Logic) Create a move action for the target with a callback when reaching the bottom // Create and run the actions CCMoveTo* moveTarget = [CCMoveTo actionWithDuration:actualDuration ! ! ! position:ccp(actualX, -target.contentSize.height/2)]; CCCallFuncN* actionForTargetMoveDidFinish = [CCCallFuncN actionWithTarget:self selector:@selector(targetMoveFinished:)]; [target runAction:[CCSequence actions:moveTarget, actionForTargetMoveDidFinish, nil]]; Thursday, June 21, 12
  • 49. Step 3: Adding Bad Guys (Game Logic) Add the callback method for a target that dies or reaches the bottom // Method for removing a target that has died or reached the bottom -(void)targetMoveFinished:(id)sender { ! CCSprite *target = (CCSprite *)sender; [self removeChild:target cleanup:YES]; ! [_targets removeObject:target]; } Thursday, June 21, 12
  • 50. Step 3: Adding Bad Guys (Game Logic) Thursday, June 21, 12
  • 51. Step 4: Killing Bad Guys (Adding UI) Detect the touch - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { ! // Choose one of the touches to work with ! UITouch *touch = [touches anyObject]; ! CGPoint location = [touch locationInView:[touch view]]; ! location = [[CCDirector sharedDirector] convertToGL:location]; ! if (!_isShooting) { _isShooting = YES; Thursday, June 21, 12
  • 52. Step 4: Killing Bad Guys (Adding UI) Create the bullet // Create the bullet CCSpriteFrame* bulletFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"bullet.png"]; CCSprite* bulletSprite = [CCSprite spriteWithSpriteFrame:bulletFrame]; bulletSprite.position = _player.position; // Bullet actions CCCallFuncN* actionForRemoveBullet = [CCCallFuncN actionWithTarget:self selector:@selector(removeBullet:)]; CCMoveBy* bulletMoveBy = [CCMoveBy actionWithDuration:1.0f position:ccp(winSize.width, 0)]; [bulletSprite runAction:[CCSequence actionOne:bulletMoveBy two:actionForRemoveBullet]]; // Add bullet to layer and array [self addChild:bulletSprite]; [_bullets addObject:bulletSprite]; Thursday, June 21, 12
  • 53. Step 4: Killing Bad Guys (Adding UI) Thursday, June 21, 12
  • 54. Step 5: Check for Bad Guy Death -(void)update:(ccTime)dt { CCSprite* bulletToRemove = nil; for (CCSprite *bullet in _bullets) { for (CCSprite* target in _targets) { CGRect targetBox = CGRectMake(target.position.x, target.position.y, [target boundingBox].size.width, [target boundingBox].size.height); // Check if bullet is in the target's bounding box if (CGRectContainsPoint(targetBox, bullet.position)) { // Animate target death and remove target bulletToRemove = bullet; } } } // Remove bullet if target was hit if (bulletToRemove != nil) { [self removeChild:bulletToRemove cleanup:YES]; [_bullets removeObject:bulletToRemove]; } } Thursday, June 21, 12
  • 55. Step 5: Check for Bad Guy Death Thursday, June 21, 12
  • 56. Step 6: Animating Our Hero Preload the animation from the spritesheet (In init) // Load the animation for player NSMutableArray *animFrames1 = [NSMutableArray array]; for (int i = 1; i < 12; i++) { CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"player_%02d.png",i]]; ! [animFrames1 addObject:frame]; } [[CCAnimationCache sharedAnimationCache] addAnimation:[CCAnimation animationWithFrames:animFrames1 delay:FRAME_DELAY] name:@"player"];! Thursday, June 21, 12
  • 57. Step 6: Animating Our Hero Animate the hero when shooting (In ccTouchesEnded) // Actions for shooting animation CCCallFunc* actionForShootDidEnd = [CCCallFunc actionWithTarget:self selector:@selector(shootDidEnd)]; CCAnimation* playerShootAnimation = [[CCAnimationCache sharedAnimationCache] animationByName:@"player"]; CCAnimate* shootAnimate = [CCAnimate actionWithAnimation:playerShootAnimation]; [_player runAction:[CCSequence actionOne:shootAnimate two:actionForShootDidEnd]]; Thursday, June 21, 12
  • 58. Step 6: Animating Our Hero Thursday, June 21, 12
  • 59. Step 7: Animating Bad Guys Dying (in update) // Set up actions for animation and target removal CCCallFuncN* actionForDeathDidFinish = [CCCallFuncN actionWithTarget:self selector:@selector(targetMoveFinished:)]; CCAnimate* deathAnimation = [CCAnimate actionWithAnimation:[[CCAnimationCache sharedAnimationCache] animationByName:@"death"] restoreOriginalFrame:NO]; [target runAction:[CCSequence actionOne:deathAnimation two:actionForDeathDidFinish]]; Thursday, June 21, 12
  • 60. Step 7: Animating Bad Guys Dying Thursday, June 21, 12
  • 61. Step 8: Adding Body Count (In init) NSString* bodyCountString = [NSString stringWithFormat:@"%d", _bodyCount]; _labelCount = [CCLabelTTF labelWithString:bodyCountString fontName:@"Arial" fontSize:16]; _labelCount.color = ccc3(0,0,0); _labelCount.position = ccp(110, winSize.height - 16); [self addChild:_labelCount z:2]; (In ccTouchesEnded) _bodyCount++; NSString* bodyCountString = [NSString stringWithFormat:@"%d", _bodyCount];! [_labelCount setString:bodyCountString]; Thursday, June 21, 12
  • 62. Step 8: Adding Body Count Thursday, June 21, 12
  • 63. Step 9: Adding Sound & Music (In init) ! // Start background music, set lower volume ! SimpleAudioEngine.sharedEngine.backgroundMusicVolume = 0.4f; ! [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"explosive_attack.mp3"]; (In ccTouchesEnded) ! // Play sound effect on every shot and on death ! [[SimpleAudioEngine sharedEngine] playEffect:@"shot.wav"]; ! [[SimpleAudioEngine sharedEngine] playEffect:@"death.wav"]; Thursday, June 21, 12
  • 64. Step 9: Adding Sound & Music Thursday, June 21, 12
  • 66. Para-Shoot 2.0 Enemies can move and attack Joypad + HUD Move our hero Different weapons, power ups and health Game menu and high scores Levels Save/Load Game Refactor code (More scenes and layers) Thursday, June 21, 12
  • 67. Refactoring Para-Shoot Scenes: Loss Intro Main Menu Level X Victory Options High Score Layers: Level X Background Player Bad Guys Joypad/HUD Thursday, June 21, 12
  • 68. More stuff to explore ★ Physics Engines - Chipmunk and Box2D ★ Particle System ★ Tilemaps ★ Menu Interface Thursday, June 21, 12
  • 69. Where can you learn more Cocos2D Demo Library (Comes with Cocos) Wiki: http://cocos2d-iphone.org/wiki Ray Wenderlich: http://www.raywenderlich.com Steffen Itterheim: http://learn-cocos2d.com Sapus Tongue Source Code: http://www.sapusmedia.com/sources Thursday, June 21, 12
  • 70. Thank You! Yaron Karasik yaronkarasik@gmail.com @Greenwell Thursday, June 21, 12