Cocos2d Cross-Platform Game Development Cookbook - Second Edition

Develop games for iOS and Android using Cocos2d with the aid of over 70 step-by-step recipes

Cocos2d Cross-Platform Game Development Cookbook - Second Edition

This ebook is included in a Mapt subscription
Siddharth Shekar

1 customer reviews
Develop games for iOS and Android using Cocos2d with the aid of over 70 step-by-step recipes
$0.00
$20.00
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781784393236
Paperback384 pages

Book Description

Cocos2d is the world’s leading game development framework for developing iOS games. With the introduction of Swift and Spritebuilder, it has become easier than ever to develop the games of your dreams without much effort. With Cocos2d, you can also deploy the game on Android, thereby maximizing profit and reducing development and porting costs.

The book starts off with a detailed look at how to implement sprites and animations into your game to make it livelier. You will then learn to add scenes to the game such as the gameplay scene and options scene and create menus and buttons in these scenes, as well as creating transitions between them. From there on, you will get an understanding of how to program user interactions such as tapping, holding, and swiping. You’ll then add accelerometer inputs and physics to the scene, and make objects respond back to the inputs. A game is practically incomplete without audio being added, so this will be covered next.

The next section will include ways to add Artificial Intelligence to enemies in the game, allowing them to patrol, chase, and shoot in a projectile manner. You will then learn to use NSUserDefault to save and load game progress, and create and access files using JSON, Plist, and XML files for custom storage and retrieval of data. Then you will learn to add dynamic lighting to your game and will use industry-wide tools such as Texture Packer, Glyph Designer, Physics Editor, Particle Designer, and Sprite Illuminator to create more visually appealing and performance-optimized games.

Towards the end of the book, we dive into Apple’s latest programming language—Swift, highlighting the major differences between Objective C and Swift. The book culminates with taking your existing game developed for iOS and porting it to Android, showing you how to install the Android Xcode plugin as well.

Table of Contents

Chapter 1: Sprites and Animations
Introduction
Downloading and installing Cocos2d
The 2D coordinate system
Getting access to MainScene
Adding sprites to scenes
Creating a sprite using RenderTexture
Creating a custom sprite class
Animating sprites
Adding actions to sprites
Drawing glPrimitives
Adding the parallax effect
Chapter 2: Scenes and Menus
Introduction
Adding a MainMenu Scene
Adding text using CCLabel
Adding buttons with CCMenu
Adding a Gameplay Scene
Transitioning between scenes
Adding transition effects
Adding a Level Selection Scene
Scrolling a Level Selection Scene
Chapter 3: Gestures, Touches, and the Accelerometer
Introduction
Understanding swipe
Implementing tap
Adding LongPress
Adding pinch/zoom controls
Adding rotation objects
Adding panning
Including touches
Creating objects with touchBegan
Moving objects with touchMoved
Customizing touches in the sprite class
Adding an accelerometer
Adding a directional pad
Chapter 4: Physics
Introduction
Adding physics to a game scene
Adding physics objects
Looking at different body types
Adding sprite texture to physics objects
Creating composite bodies
Creating complex shapes
Changing body properties
Applying impulse with the touch control
Applying force with the accelerometer
Collision detection
Adding revolute joints
Adding motor joints
Adding a game loop and scoring
Chapter 5: Audio
Introduction
Adding background music
Adding audio effects
Adding a mute button
Adding a volume slider
Adding a pause and resume button
Chapter 6: AI and A* Pathfinding
Introduction
Patrol enemy behavior
Projectile shooting enemy
Chasing enemy behavior
A* pathfinding
Chapter 7: Data Storage and Retrieval
Introduction
Loading the XML file data
Saving to the XML file data
Loading the JSON file data
Loading the PLIST file data
Saving the PLIST file data
Using NSUserDefaults
Chapter 8: Effects
Introduction
CCEffects
Adding the glass effect
Adding the motion streak effect
Adding the particle effect
Adding 2D lighting
Chapter 9: Game Tools
Introduction
Glyph Designer
Particle system
TexturePacker
PhysicsEditor
Chapter 10: Swift/SpriteBuilder Basics
Introduction
Implementing the Swift syntax
Implementing Cocos2d Swift
SpriteBuilder basics
Chapter 11: Porting to Android
Introduction
Installing the Android Xcode plugin
Enabling USB debugging on a device
Running the SpriteBuilder project on a device
Porting a project to Android
No Java runtime error
Provision profile error
Blank screen error
Useful resources

What You Will Learn

  • Build custom sprites with custom animations for the game
  • Build interactivity into your game by adding gestures and touch interactions
  • Understand AI enemy programming and path finding to make games more exciting
  • Add physics to your game to make it more lively and interactive
  • Get familiar with the Swift and Sprite builder implementations along with Objective-C programming
  • Perform hassle-free deployment of games built in iOS onto Android
  • Add effects and particle systems to make the game more colorful

Authors

Table of Contents

Chapter 1: Sprites and Animations
Introduction
Downloading and installing Cocos2d
The 2D coordinate system
Getting access to MainScene
Adding sprites to scenes
Creating a sprite using RenderTexture
Creating a custom sprite class
Animating sprites
Adding actions to sprites
Drawing glPrimitives
Adding the parallax effect
Chapter 2: Scenes and Menus
Introduction
Adding a MainMenu Scene
Adding text using CCLabel
Adding buttons with CCMenu
Adding a Gameplay Scene
Transitioning between scenes
Adding transition effects
Adding a Level Selection Scene
Scrolling a Level Selection Scene
Chapter 3: Gestures, Touches, and the Accelerometer
Introduction
Understanding swipe
Implementing tap
Adding LongPress
Adding pinch/zoom controls
Adding rotation objects
Adding panning
Including touches
Creating objects with touchBegan
Moving objects with touchMoved
Customizing touches in the sprite class
Adding an accelerometer
Adding a directional pad
Chapter 4: Physics
Introduction
Adding physics to a game scene
Adding physics objects
Looking at different body types
Adding sprite texture to physics objects
Creating composite bodies
Creating complex shapes
Changing body properties
Applying impulse with the touch control
Applying force with the accelerometer
Collision detection
Adding revolute joints
Adding motor joints
Adding a game loop and scoring
Chapter 5: Audio
Introduction
Adding background music
Adding audio effects
Adding a mute button
Adding a volume slider
Adding a pause and resume button
Chapter 6: AI and A* Pathfinding
Introduction
Patrol enemy behavior
Projectile shooting enemy
Chasing enemy behavior
A* pathfinding
Chapter 7: Data Storage and Retrieval
Introduction
Loading the XML file data
Saving to the XML file data
Loading the JSON file data
Loading the PLIST file data
Saving the PLIST file data
Using NSUserDefaults
Chapter 8: Effects
Introduction
CCEffects
Adding the glass effect
Adding the motion streak effect
Adding the particle effect
Adding 2D lighting
Chapter 9: Game Tools
Introduction
Glyph Designer
Particle system
TexturePacker
PhysicsEditor
Chapter 10: Swift/SpriteBuilder Basics
Introduction
Implementing the Swift syntax
Implementing Cocos2d Swift
SpriteBuilder basics
Chapter 11: Porting to Android
Introduction
Installing the Android Xcode plugin
Enabling USB debugging on a device
Running the SpriteBuilder project on a device
Porting a project to Android
No Java runtime error
Provision profile error
Blank screen error
Useful resources

Book Details

ISBN 139781784393236
Paperback384 pages
Read More
From 1 reviews

Read More Reviews