Top Banner
Cross Platform Game Programming with Cocos2d-JS So Cal Code Camp - Fullerton - 8 March 2015 Troy Miles
59

Cross Platform Game Programming with Cocos2d-js

Jul 14, 2015

Download

Software

Troy Miles
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cross Platform Game Programming with Cocos2d-js

Cross Platform Game Programming with Cocos2d-JSSo Cal Code Camp - Fullerton - 8 March 2015 Troy Miles

Page 2: Cross Platform Game Programming with Cocos2d-js
Page 3: Cross Platform Game Programming with Cocos2d-js
Page 4: Cross Platform Game Programming with Cocos2d-js

Troy MilesTroy Miles aka the RocknCoder

Over 35 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 5: Cross Platform Game Programming with Cocos2d-js
Page 6: Cross Platform Game Programming with Cocos2d-js

Contacting Me

@therockncoder

[email protected]

http://therockncoder.com/

https://github.com/Rockncoder

https://www.youtube.com/user/rockncoder

Page 7: Cross Platform Game Programming with Cocos2d-js

Text

https://bitly.com/bundles/rockncoder/5

Page 8: Cross Platform Game Programming with Cocos2d-js

Agenda

What is Cocos2d-JS?

Setting Up Your Environment

Parts is Parts

Workflow

Page 9: Cross Platform Game Programming with Cocos2d-js

Why make mobile games?

Page 10: Cross Platform Game Programming with Cocos2d-js
Page 11: Cross Platform Game Programming with Cocos2d-js
Page 12: Cross Platform Game Programming with Cocos2d-js

Titles using Cocos2d-x

Page 13: Cross Platform Game Programming with Cocos2d-js

Text

Avengers AllianceMarvel Entertainment

Page 14: Cross Platform Game Programming with Cocos2d-js

Text

Family Guy: The Quest for StuffTinyCo, Inc.

Page 15: Cross Platform Game Programming with Cocos2d-js

Diamond DashWooga

Page 16: Cross Platform Game Programming with Cocos2d-js

Star Wars: Tiny Death StarLucasArts

Page 17: Cross Platform Game Programming with Cocos2d-js

BADLANDFrogmind

Page 18: Cross Platform Game Programming with Cocos2d-js
Page 19: Cross Platform Game Programming with Cocos2d-js

Cocos2d-JS

History

Cocos2d-JS

Platforms and Restrictions

Page 20: Cross Platform Game Programming with Cocos2d-js

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 21: Cross Platform Game Programming with Cocos2d-js

Cocos2d-JS

Cocos2d-x JavaScript version

Full Cocos2d-x functionality

Simplified JavaScript friendly API

Code Once, Run Everywhere

Mobile Native, Desktop, Web

Page 22: Cross Platform Game Programming with Cocos2d-js
Page 23: Cross Platform Game Programming with Cocos2d-js

Platforms

Mac OS X

Windows

Page 24: Cross Platform Game Programming with Cocos2d-js

Mac OS X

iOS

Android

HTML 5

Mac OS X

Page 25: Cross Platform Game Programming with Cocos2d-js

Windows

Windows 7

Android

HTML5

Windows Phone 8 (soon)

Page 26: Cross Platform Game Programming with Cocos2d-js

Prerequisites

Page 27: Cross Platform Game Programming with Cocos2d-js

Android

Java 7

Android ADT/Eclipse (NOT Android Studio)

Android NDK

Page 28: Cross Platform Game Programming with Cocos2d-js

iOS

Xcode

Page 29: Cross Platform Game Programming with Cocos2d-js

HTML5

No extra prerequisites

Page 30: Cross Platform Game Programming with Cocos2d-js

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 31: Cross Platform Game Programming with Cocos2d-js

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 32: Cross Platform Game Programming with Cocos2d-js

Installation

http://cocos2d-x.org/download

Unzip the file

execute ./setup.py

Page 33: Cross Platform Game Programming with Cocos2d-js

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 js files

Page 34: Cross Platform Game Programming with Cocos2d-js

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 35: Cross Platform Game Programming with Cocos2d-js

Parts is Parts

Project Files & Folders

Terminology

Coordinate system

Page 36: Cross Platform Game Programming with Cocos2d-js

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 37: Cross Platform Game Programming with Cocos2d-js

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 38: Cross Platform Game Programming with Cocos2d-js

The code flow

index.html

main.js's

app.js

Page 39: Cross Platform Game Programming with Cocos2d-js

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 40: Cross Platform Game Programming with Cocos2d-js

More terminology

Action - an order given to a node, like animations

Menu - Creates an onscreen menu

LabelTTF - The simplest option for displaying text

Page 41: Cross Platform Game Programming with Cocos2d-js

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 42: Cross Platform Game Programming with Cocos2d-js

Workflow

Program Editor

Deploying

Modifying

Debugging

Page 43: Cross Platform Game Programming with Cocos2d-js

Program editorI use WebStorm 9

It is available for Windows, Mac, and Linux

It has a Chrome extension, JetBrains IDE Support, allows debugging

Page 44: Cross Platform Game Programming with Cocos2d-js

Deploying

Choose

Right click on index.html

Click Debug “index.html”

Page 45: Cross Platform Game Programming with Cocos2d-js

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 46: Cross Platform Game Programming with Cocos2d-js

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 47: Cross Platform Game Programming with Cocos2d-js

Let’s look at a gameParts

Scenes

Player

User Input

Physics plug-in

Collision detection

Page 48: Cross Platform Game Programming with Cocos2d-js

Audio

File formats

Sounds

Music

Page 49: Cross Platform Game Programming with Cocos2d-js

File formats

All of the devices can play mp3

Only some of the browsers can

Page 50: Cross Platform Game Programming with Cocos2d-js
Page 51: Cross Platform Game Programming with Cocos2d-js

Playing sounds

Playing sounds is easy

Simply call the audioEngine’s playEffect method

Page 52: Cross Platform Game Programming with Cocos2d-js

Cocos Studio + Other Tools

Animation Editor

UI Editor

Scene Editor

Data Editor

Tiled

Page 53: Cross Platform Game Programming with Cocos2d-js

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 54: Cross Platform Game Programming with Cocos2d-js

Android

$25 for a lifetime

Anyone can put apps on a device

Page 55: Cross Platform Game Programming with Cocos2d-js

MaterialsSigned app

Icons

Screenshots

Big Images

Descriptions

Website

Videos

Page 56: Cross Platform Game Programming with Cocos2d-js

Resources

http://www.cocos2d-x.org/

http://www.mapeditor.org/

http://therockncoder.blogspot.com/

Page 57: Cross Platform Game Programming with Cocos2d-js

Sounds and Graphics

http://www.nosoapradio.us/

http://www.freesound.org/

http://spritedatabase.net/

http://opengameart.org/

Page 58: Cross Platform Game Programming with Cocos2d-js

Summary

Cocos2d-JS allows you to create fast cross platform games in JavaScript

Installation & documentation are a bit rough

No support for Window Phone 8

Page 59: Cross Platform Game Programming with Cocos2d-js

Text

https://bitly.com/bundles/rockncoder/5