This document discusses an introductory presentation on mobile game programming with Cocos2d-JS. It provides an overview of the speaker's background and experience, outlines the agenda which includes an introduction to Cocos2d-JS, setting up the environment, terminology, workflow, looking at a sample game, audio, tools, ads and publishing. It also discusses platforms supported, prerequisites, installation, common commands, game development parts and terminology, the coordinate system, debugging and promoting games.
Introduction to Mobile Game Programming with Cocos2d-JS
1. Intro to Mobile Game
Programming with Cocos2d-JS
2014 - So Cal Code Camp - San Diego
Troy Miles
2. Troy Miles
Troy 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
18. History
2008 - 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
28. 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
29. Python 2
The cocos command
line needs python to run
python 2.7.5+
It won’t work with
python 3
https://www.python.org/
downloads/
31. 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
32. cocos new
cocos new -l js
cocos new -l js —no-native
cocos new projectName -l js -d ./Projects
cocos new projectName -l js
34. Project files and folders
frameworks/runtime/tools
res - your resources
src - your JS source code
project.json - configuration
main.js - JS boot code
index.html - HTML markup
35. 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
38. Terminology
cc - 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
39. More terminology
Action - an order given to a node, like animations
Menu - Creates an onscreen menu
LabelTTF - The simplest option for displaying text
40. 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
44. 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
45. 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
46. Let’s look at a game
Parts
Scenes
Player
User Input
Physics plug-in
Collision detection
54. 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