O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Cocos2d-JS Game Development

Book Description

Learn to create robust and engaging cross-platform HTML5 games using Cocos2D-JS

In Detail

Whether you are new to game development or an experienced developer, you will be surprised by how easy it is to create HTML5 cross-platform games with Cocos2d-JS. In this book, you will use JavaScript to create spectacular and exciting games of different genres.

Without any dreary theory, which often discourages technical book readers, each chapter will guide you through the creation of different games, each packed with new and exciting features.

You will begin by learning the basics of a cross-platform game. You'll also learn to animate, rotate, scroll, and tween sprites. You will learn to make your game more enticing by adding your own special touch using features such as music, sound effects, and physics. You'll also learn to protect, sitelock, export, and publish the games you have created. By the end of the book, you'll have created a complete cross-platform game right from scratch, featuring leader boards and third-party adverts, complete with the final polish every game should require.

What You Will Learn

  • Discover the basics behind each game genre, from endless runners to puzzles, and from physics games to match games
  • Target different resolutions, screen sizes, screen ratios, and deal with landscape and portrait screens
  • Place and move sprites on the screen, using scrolling and tweening for smooth movements
  • Enhance your game by adding sound effects and background music
  • Create physics-driven games with unmatched realism
  • Create and destroy bodies with a single touch while managing forces, collisions, and gravity
  • Improve your game's visual appeal by adding particles to generate explosions, fire trails, and other appealing effects
  • Manage resources and save memory by packing all your graphic assets in a single file

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Learning Cocos2d-JS Game Development
    1. Table of Contents
    2. Learning Cocos2d-JS Game Development
    3. Credits
    4. Foreword
    5. Foreword
    6. About the Author
    7. About the Reviewers
    8. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    9. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    10. 1. Hello World – A Cross-platform Game
      1. Why should I make cross-platform games?
      2. What Cocos2d-JS is and how it works
        1. Requirements to run Cocos2d-JS
      3. The structure of your Cocos2d-JS project
      4. Hello Cross-World
      5. Preloading and adding images
      6. Removing images and changing the background color
      7. Summary
    11. 2. Adding Interactivity – The Making of a Concentration Game
      1. Creating multiple instances of game assets
      2. Adding a gradient background
      3. Extending the Sprite class beyond its capabilities
      4. Making assets react to clicks and touches
        1. Picking a tile as an initial attempt
      5. Changing sprite images on the fly
        1. Showing the tile picture
      6. Shuffling the tiles and adding the score
      7. Summary
    12. 3. Moving Sprites Around the Screen – An Endless Runner
      1. Loading and placing graphic resources
      2. Adding an endless scrolling background
      3. Adding the spaceship
      4. Controlling the spaceship
      5. Adding asteroids
      6. Asteroid versus spaceship collision
      7. Invulnerability
      8. Preventing the spaceship from flying off the screen
      9. Adding particles
      10. Summary
    13. 4. Learn about Swipes through the making of Sokoban
      1. Loading graphic assets
      2. Building a level
      3. Detecting swipes
      4. Completing the game
      5. Summary
    14. 5. Become a Musical Maestro
      1. Choosing sounds
      2. Preloading sounds
      3. Creating a sound menu
      4. Managing music and sound effects
      5. Summary
    15. 6. Controlling the Game with Virtual Pads
      1. Overview of virtual pads
      2. First things first – the game
        1. Controlling the cart with ghost buttons
        2. Controlling the cart with a virtual pad
        3. Controlling the cart just with your finger
      3. Summary
    16. 7. Adding Physics to Your Games Using the Box2D Engine
      1. Before you start
      2. Adding the Box2D engine to your project
      3. Configuring the physics world
      4. Adding bodies to the world
      5. Updating sprite position as the world changes
      6. Selecting and destroying world bodies
      7. Checking for collisions among bodies
      8. Summary
    17. 8. Adding Physics to Your Games Using the Chipmunk2D Engine
      1. Adding the Chipmunk2D engine to your project
        1. A physics game, without physics
      2. Configuring the physics space
      3. Adding bodies to the space
        1. Updating Chipmunk2D space and using debug draw
      4. Selecting and destroying space bodies
      5. Checking for collisions among bodies
      6. Using your own graphic assets
      7. Summary
    18. 9. Creating Your Own Blockbuster Game – A Complete Match 3 Game
      1. Setting up the game
        1. Creating the board
        2. Selecting and deselecting the first globe
        3. Making globez chains
        4. Backtracking
        5. Removing globez
        6. Making the globez fall down
        7. Creating new globez
        8. Bonus – using the drawing API for a visual feedback
      2. Where to go now
        1. Protect your code
        2. Port your game on mobile devices as a native app
        3. Publishing your game
        4. Licensing your game
        5. Staying up-to-date
      3. Summary
    19. Index