![Page 1: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/1.jpg)
Intro to Mobile Game Programming with Cocos2d-JS2014 - So Cal Code Camp - San Diego Troy Miles
![Page 2: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/2.jpg)
Troy MilesTroy Miles aka the RocknCoder
Over 30 years of programming experience
Wrote a few games for Interplay in the 80's and 90’s
Speaker and writer on all things web & mobile
![Page 3: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/3.jpg)
Contacting Me
@therockncoder
http://therockncoder.blogspot.com/
https://github.com/Rockncoder
https://www.youtube.com/user/rockncoder
![Page 5: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/5.jpg)
Agenda, Session 1
What is Cocos2d-JS?
Setting Up Your Environment
Parts is Parts
Workflow
![Page 6: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/6.jpg)
Agenda, Session 2Let’s look at a game
Audio
Cocos Studio + Other Tools
Ads
Publishing
Promoting
![Page 7: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/7.jpg)
Why make mobile games?
![Page 8: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/8.jpg)
![Page 9: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/9.jpg)
![Page 10: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/10.jpg)
Titles using Cocos2d-x
![Page 11: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/11.jpg)
Text
Avengers AllianceMarvel Entertainment
![Page 12: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/12.jpg)
Text
Family Guy: The Quest for StuffTinyCo, Inc.
![Page 13: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/13.jpg)
Diamond DashWooga
![Page 14: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/14.jpg)
Star Wars: Tiny Death StarLucasArts
![Page 15: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/15.jpg)
BADLANDFrogmind
![Page 16: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/16.jpg)
![Page 17: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/17.jpg)
Cocos2d-JS
History
Cocos2d-JS
Platforms and Restrictions
![Page 18: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/18.jpg)
History2008 - Ricardo Quesada, a game developer in Argentina, writes a game framework named Cocos2d
2009 - After the iPhone SDK release, Cocos2d rewritten in Objective-C to become Cocos2d-iPhone
2010 - Zhe Wang, a developer in China, creates a fork, Cocos2d-x
Chukong Technologies Inc, Zhe's company, develops Cocos2d-JS, -HTML5, and -Lua
![Page 19: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/19.jpg)
Cocos2d-JS
Cocos2d-x JavaScript version
Full Cocos2d-x functionality
Simplified JavaScript friendly API
Code Once, Run Everywhere
Mobile Native, Desktop, Web
![Page 20: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/20.jpg)
![Page 21: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/21.jpg)
Platforms
Mac OS X
Windows
![Page 22: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/22.jpg)
Mac OS X
iOS
Android
HTML 5
Mac OS X
![Page 23: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/23.jpg)
Windows
Windows 7
Android
HTML5
Windows Phone 8 (soon)
![Page 24: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/24.jpg)
Prerequisites
![Page 25: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/25.jpg)
Android
Java 6 or 7
Android ADT (NOT Android Studio)
Android NDK
![Page 26: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/26.jpg)
iOS
Xcode
![Page 27: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/27.jpg)
HTML5
No extra prerequisites
![Page 28: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/28.jpg)
Desktops
You can also build desktop apps for Windows and Mac OS X
You will need Visual Studio and Xcode respectively
I won’t speak further about this
![Page 29: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/29.jpg)
Python 2The cocos command line needs python to run
python 2.7.5+
It won’t work with python 3
https://www.python.org/downloads/
![Page 30: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/30.jpg)
Installation
http://cocos2d-x.org/download
Unzip the file
execute ./setup.py
![Page 31: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/31.jpg)
cocos command options
new - Creates a new project
compile - Compiles the current project to binary
deploy - Deploy a project to the target
run - Compiles & deploy project and then runs it on the target
jscompile - minifies and/or compiles js files
![Page 32: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/32.jpg)
cocos new
cocos new -l js
cocos new -l js —no-native
cocos new projectName -l js -d ./Projects
cocos new projectName -l js
![Page 33: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/33.jpg)
Parts is Parts
Project Files & Folders
Terminology
Coordinate system
![Page 34: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/34.jpg)
Project files and foldersframeworks/runtime/tools
res - your resources
src - your JS source code
project.json - configuration
main.js - JS boot code
index.html - HTML markup
![Page 35: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/35.jpg)
project.json
debug - the current debug setting
showFPS - whether or not to show the frame rate
frameRate - the desired frame rate
modules - cocos2d and potentially plugins
jsList - all of your source code
![Page 36: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/36.jpg)
Demo time
![Page 37: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/37.jpg)
The code flow
index.html
main.js's
app.js
![Page 38: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/38.jpg)
Terminologycc - Cocos2d, most classes prepended with this
Director - takes care of navigation between scenes
Node - Almost every element is a node
Scene - a screen in your game
Sprite - a 2D image that can be moved, rotated, scaled & more
Layer - a special node which accepts user input
![Page 39: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/39.jpg)
More terminology
Action - an order given to a node, like animations
Menu - Creates an onscreen menu
LabelTTF - The simplest option for displaying text
![Page 40: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/40.jpg)
Right handed coordinate system
Different than web
Origin (0,0) located at lower left hand of screen
x position increases going right
y position increases going up
max x,y at upper right hand corner
![Page 41: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/41.jpg)
Workflow
Program Editor
Deploying
Modifying
Debugging
![Page 42: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/42.jpg)
Program editorI used WebStorm 8
It is available for Windows, Mac, and Linux
It has a Chrome extension, JetBrains IDE Support, allows debugging
![Page 43: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/43.jpg)
Deploying
Choose
Right click on index.html
Click Debug “index.html”
![Page 44: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/44.jpg)
Modifying
Double tap a file to open it in the editor
Modify the text as desire
Click the refresh icon to run the code again
![Page 45: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/45.jpg)
Debugging
To set a break point, click in the gutter to the left of the text
To set a conditional breakpoint, right click it and specify a condition
Click again to delete it
![Page 46: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/46.jpg)
Let’s look at a gameParts
Scenes
Player
User Input
Physics plug-in
Collision detection
![Page 47: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/47.jpg)
Audio
File formats
Sounds
Music
![Page 48: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/48.jpg)
File formats
All of the devices can play mp3
Only some of the browsers can
![Page 49: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/49.jpg)
![Page 50: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/50.jpg)
Playing sounds
Playing sounds is easy
Simply call the audioEngine’s playEffect method
![Page 51: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/51.jpg)
Cocos Studio + Other Tools
Animation Editor
UI Editor
Scene Editor
Data Editor
Tiled
![Page 52: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/52.jpg)
Ads
Ads are tough since there is no readily available JS module
AdMob / AdSense
iAds
Microsoft Ads
![Page 53: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/53.jpg)
Publishing
Becoming a developer
Materials
Deploying
![Page 54: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/54.jpg)
iOS
$99 a year for an individual in the local currency
$299 for an enterprise
Free for the university program
Only developers can put apps on devices
![Page 55: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/55.jpg)
Android
$25 for a lifetime
Anyone can put apps on a device
![Page 56: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/56.jpg)
MaterialsSigned app
Icons
Screenshots
Big Images
Descriptions
Website
Videos
![Page 57: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/57.jpg)
Promoting
Family and Friends
Social Media
Web site
Advertising
![Page 58: Introduction to Mobile Game Programming with Cocos2d-JS](https://reader034.vdocuments.site/reader034/viewer/2022042510/554bbc23b4c90594278b4dd6/html5/thumbnails/58.jpg)
Summary
Cocos2d-JS allows you to create fast cross platform games
Installation and setup can be a bit tough
Monetizing with Ads is also tough