Learning Cocos2d-JS Game Development
()
About this ebook
- Create HTML5 games running both on desktop and mobile devices, played with both mouse and touch controls
- Add advanced features such as realistic physics, particle effects, scrolling, tweaking, sound effects, background music, and more to your games
- Build exciting cross-platform games and build a memory game, an endless runner and a physics-driven game
If you are new to game development or have just gotten your teeth into developing games but desire to learn more, then this book is for you. An understanding of the essentials of JavaScript is required.
Related to Learning Cocos2d-JS Game Development
Related ebooks
Cocos2d-x Game Development Blueprints Rating: 0 out of 5 stars0 ratingsBuilding Android Games with Cocos2d-x Rating: 0 out of 5 stars0 ratingsAndroid Game Programming by Example Rating: 0 out of 5 stars0 ratingsLearning Cocos2d-x Game Development Rating: 0 out of 5 stars0 ratingsCocos2D Game Development Essentials Rating: 0 out of 5 stars0 ratingsBuilding a 3D Game with LibGDX Rating: 1 out of 5 stars1/5Unity 2022 by Example: A project-based guide to building 2D and 3D games, enhanced for AR, VR, and MR experiences Rating: 0 out of 5 stars0 ratingsBeginning Android C++ Game Development Rating: 0 out of 5 stars0 ratingsGodot Engine Game Development Projects: Build five cross-platform 2D and 3D games with Godot 3.0 Rating: 3 out of 5 stars3/5Godot 4 Game Development Projects: Build five cross-platform 2D and 3D games using one of the most powerful open source game engines Rating: 0 out of 5 stars0 ratingsBeginning Unity Android Game Development: From Beginner to Pro Rating: 0 out of 5 stars0 ratingsMind-Melding Unity and Blender for 3D Game Development: Unleash the power of Unity and Blender to create amazing games Rating: 0 out of 5 stars0 ratingsUnity 2018 By Example: Learn about game and virtual reality development by creating five engaging projects, 2nd Edition Rating: 0 out of 5 stars0 ratingsCreating Games with cocos2d for iPhone 2 Rating: 0 out of 5 stars0 ratingsMastering iOS Game Development: Master the advanced concepts of game development for iOS to build impressive games Rating: 0 out of 5 stars0 ratingsGame Development with Unity for .NET Developers: The ultimate guide to creating games with Unity and Microsoft Game Stack Rating: 0 out of 5 stars0 ratingsLearning Android Game Development Rating: 0 out of 5 stars0 ratingsCocos2d Game Development Blueprints Rating: 0 out of 5 stars0 ratingsBox2D for Flash Games Rating: 0 out of 5 stars0 ratingsLearning Unreal® Engine iOS Game Development Rating: 0 out of 5 stars0 ratingsHands-On Game Development without Coding: Create 2D and 3D games with Visual Scripting in Unity Rating: 0 out of 5 stars0 ratingsBuilding your First Mobile Game using XNA 4.0 Rating: 0 out of 5 stars0 ratingsiOS Game Development By Example Rating: 0 out of 5 stars0 ratingsMonoGame Mastery: Build a Multi-Platform 2D Game and Reusable Game Engine Rating: 0 out of 5 stars0 ratingsBeginning Android Games Development: From Beginner to Pro Rating: 0 out of 5 stars0 ratingsGodot from Zero to Proficiency (Beginner): Godot from Zero to Proficiency, #2 Rating: 5 out of 5 stars5/5Godot from Zero to Proficiency (Advanced): Godot from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5Learning LibGDX Game Development - Second Edition Rating: 0 out of 5 stars0 ratings
Programming For You
SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5C# Programming from Zero to Proficiency (Beginner): C# from Zero to Proficiency, #2 Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Mastering Windows PowerShell Scripting Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsGrokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsLinux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsC Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsC All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5HTML in 30 Pages Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Coding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratingsC++ Learn in 24 Hours Rating: 0 out of 5 stars0 ratings
Reviews for Learning Cocos2d-JS Game Development
0 ratings0 reviews
Book preview
Learning Cocos2d-JS Game Development - Emanuele Feronato
Table of Contents
Learning Cocos2d-JS Game Development
Credits
Foreword
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Hello World – A Cross-platform Game
Why should I make cross-platform games?
What Cocos2d-JS is and how it works
Requirements to run Cocos2d-JS
The structure of your Cocos2d-JS project
Hello Cross-World
Preloading and adding images
Removing images and changing the background color
Summary
2. Adding Interactivity – The Making of a Concentration Game
Creating multiple instances of game assets
Adding a gradient background
Extending the Sprite class beyond its capabilities
Making assets react to clicks and touches
Picking a tile as an initial attempt
Changing sprite images on the fly
Showing the tile picture
Shuffling the tiles and adding the score
Summary
3. Moving Sprites Around the Screen – An Endless Runner
Loading and placing graphic resources
Adding an endless scrolling background
Adding the spaceship
Controlling the spaceship
Adding asteroids
Asteroid versus spaceship collision
Invulnerability
Preventing the spaceship from flying off the screen
Adding particles
Summary
4. Learn about Swipes through the making of Sokoban
Loading graphic assets
Building a level
Detecting swipes
Completing the game
Summary
5. Become a Musical Maestro
Choosing sounds
Preloading sounds
Creating a sound menu
Managing music and sound effects
Summary
6. Controlling the Game with Virtual Pads
Overview of virtual pads
First things first – the game
Controlling the cart with ghost buttons
Controlling the cart with a virtual pad
Controlling the cart just with your finger
Summary
7. Adding Physics to Your Games Using the Box2D Engine
Before you start
Adding the Box2D engine to your project
Configuring the physics world
Adding bodies to the world
Updating sprite position as the world changes
Selecting and destroying world bodies
Checking for collisions among bodies
Summary
8. Adding Physics to Your Games Using the Chipmunk2D Engine
Adding the Chipmunk2D engine to your project
A physics game, without physics
Configuring the physics space
Adding bodies to the space
Updating Chipmunk2D space and using debug draw
Selecting and destroying space bodies
Checking for collisions among bodies
Using your own graphic assets
Summary
9. Creating Your Own Blockbuster Game – A Complete Match 3 Game
Setting up the game
Creating the board
Selecting and deselecting the first globe
Making globez chains
Backtracking
Removing globez
Making the globez fall down
Creating new globez
Bonus – using the drawing API for a visual feedback
Where to go now
Protect your code
Port your game on mobile devices as a native app
Publishing your game
Licensing your game
Staying up-to-date
Summary
Index
Learning Cocos2d-JS Game Development
Learning Cocos2d-JS Game Development
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2015
Production reference: 1070115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-007-5
www.packtpub.com
Credits
Author
Emanuele Feronato
Reviewers
Pradyumna Doddala
Pavel Goodanets
Marc Estruch Tena
Jialong Zhai
Commissioning Editor
Ashwin Nair
Acquisition Editor
James Jones
Content Development Editor
Samantha Gonsalves
Technical Editor
Parag Topre
Copy Editor
Relin Hedly
Project Coordinator
Sanchita Mandal
Proofreaders
Simran Bhogal
Stephen Copestake
Maria Gould
Ameesha Green
Paul Hindle
Indexer
Rekha Nair
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy
Foreword
Known by developers all over the world, Cocos2d-x has always endeavored to help developers build and port their games on iOS, Android, and many more native platforms. However, not many developers are aware that the Cocos2d-x team also provides an efficient game engine called Cocos2d-JS to assist users developing cross-native and web platform games with only one code base.
The year 2014 has certainly been a big year for Cocos2d-JS. It became more widely adopted by big companies all over the world; we've released a major version—3.0—and combined Cocos2d-html5 and Cocos2d-x JSB (JavaScript Binding) into Cocos2d-JS. It supplies your game with cross-browser and cross-platform capabilities accompanied by complete Cocos2d-x features, complete tool chain support, and simple friendly APIs. Furthermore, we reinvented the workflow for all platforms, providing a consistent development experience for whichever platform you want to distribute it to. As a result, the Code once, run everywhere principle is easily achieved and feels natural in Cocos2d-JS. With one single JavaScript code base, you can run your game on all web browsers and native platforms, including Mac OS, Windows, iOS, and Android. This will allow your game to deliver in almost all channels of distribution for better opportunities.
Today, I'm more than grateful to witness the creation of this extraordinary book. I believe this book will help us by building a bridge to our developers around the world so they can step over the language barrier. I'd love to express my special thanks to dear Feronato, the author of this amazing book. He started programming when I was a little child in diapers and he's still going strong, inspiring thousands of indie developers around the world—that's surely something!
In this book, Feronato gathered and generously shared with us his profound knowledge in game programming and Cocos2d-JS; he also included a rich collection of examples in each chapter; this, in my opinion, is one of the best ways to help learning, as readers will get a clear sense of how to apply text in the book to real work.
Here, allow me to express my honestly sincere gratitude to Emanuele Feronato for completing such an amazing book.
Hope you all enjoy this amazing book and benefit from it.
Shun Lin
Cofounder of Cocos2d-x
Foreword
As we look forward to 2015 with excitement, I wanted to look back at what we built in 2014 and share with you how important the release of this great book is to our community.
2014 has been an extraordinary year for Cocos2d-JS. Since we announced Cocos2d-JS v3.0 alpha at our spring developers conference in March, we have put our best efforts into building a great and unique game engine for our community. Our mission is to offer an easy code once, runs everywhere game development experience and lower the development threshold to bring more developers into the game industry.
Although the version was v3.0, it was the first version of Cocos2d-JS that was inherited from Cocos2d-html5 2.2.3. It has been an entirely new era in Cocos2d's JavaScript development since v3.0; here are the most important things that we have done:
Combined the Cocos2d-html5 web engine and the native Cocos2d-x JavaScript Bindings engine so that Cocos2d-JS games are equipped naturally with cross-browser and cross-platform abilities.
Provided a consistent workflow for all platforms—a best ever Code once, runs everywhere experience.
Made a great step forward in performance for both the web engine and native engine.
Built a bunch of new features such as Facebook Integration, Assets Manager, Object Pool, JS to Objective-C/JAVA reflection, and so on.
As a result, we have started to see many games released with Cocos2d-JS, especially on the Web, iOS, and Android. Today, I'm very proud to witness the very first English book on Cocos2d-JS; it really means a lot to us. Thanks to the great work of Emanuele on this book, I believe it will help many developers all around the world learn not only about Cocos2d-JS, but also game development in general. I'm also convinced that many developers, like you, our dear reader, will enter the game industry because of this book and start a great adventure with your code.
I recommend this book not only because it's the first one, but also because reading this book is a great approach to learning Cocos2d-JS. Emanuele covered all essential parts of Cocos2d-JS in this book; most importantly, he discussed all these topics with rich examples and sample codes. Furthermore, he managed to structure these examples into small games so that readers can progressively see their work turning into real games. I believe this will be a very strong motivation and will bring much fun while learning.
Again, I want to express my appreciation to Emanuele Feronato and this wonderful book. Hope you enjoy learning Cocos2d-JS with Emanuele and enjoy coding games.
Huabin LING
Lead Programmer of Cocos2d-JS
About the Author
Emanuele Feronato has been studying programming languages since the early 1980s, with a particular interest in game development. He has taught online programming for European Social Fund (ESF), and then founded a web development company in Italy.
As a game developer, Emanuele developed Flash games sponsored by the biggest game portals and his games have been played more than 90 million times. He now ports most of them on mobile platforms and develops HTML5 games, which have been featured in the most important mobile web markets, such as Amazon.
As a writer, he has worked as a technical reviewer for Packt Publishing and published the books Flash Game Development by Example and Box2D for Flash Games.
His blog, www.emanueleferonato.com, is one of the most visited blogs about indie game development.
First, I would like to thank Packt Publishing for giving me the opportunity to write this book, especially Richard Harvey, Azharuddin Sheikh, and Samantha Gonsalves for helping me improve the book quality.
The biggest thank you obviously goes to my blog readers and my Facebook fans for appreciating my work, giving me the will to write more and more. Also, thank you for playing my games. Hope you enjoy playing them as much