Hub102 - Lesson 6 - Cocos2d-js

Post on 15-Aug-2015

125 views 3 download

Transcript of Hub102 - Lesson 6 - Cocos2d-js

Lesson 6cocos2d-js

Cocos2d-JS

• History

• Family

• Cocos2d-JS

History• 2008 - Ricardo Quesada, a game developer in

Argentina, writes a game framework named cocos2d (written in Python)

• 2009 - After iPhone SDK release, cocos2d rewritten in Objective-C to become cocos2d-iphone

• 2010 - Zhe Wang, a developer in China, created a fork, cocos2d-x (Written in C++)

• Chukong Technologies Inc, Zhe’s company, develops cocos2d-JS, -HTML5, and -Lua

Family

Cocos2d-JS

• Cocos2d-x JavaScript version

• Full cocos2d-x functionality

• Simplified JavaScript friendly API

• Code One, Run Everywhere

• Mobile Native, Web, Desktop

Cocos2d-js setup• Install python 2.7.x

• Extract Android SDK, Android NDK

• Add environment PATH

• JAVA

• Ant

• run setup.py on console

• Test: run command cocos on console

Cocos Command

• new - Creates new project

• compile - Compiles the current project library

• deploy - Deploy project to target

• run - Compiles & Deploy project and then runs it on the target

• jscompile - minifies and/or compiles js fiels

Project files & folders• frameworks/runtime-src -

where you can build native client

• res - your assets

• src - your JS source code

• project.json - project configuration

• main.js - JS boot code

• index.html - html markup

Runing demo• cocos run -p web

cocos2d basic concept

cocos2d basic concept

cocos2d basic concept

cocos2d basic concept

Director & Scene

• Game made up of “game screens” called Scenes

• Each Scene can be considered a separate app

• Director handle main window and executes Scenes

Layers

• Each Scene contains several full screen Layers

• Layers contain Sprites which are game elements

• Layers useful for Controls, Background, Labels, Menus

Nodes• Nodes are anything that can gets drawn or

contains things that get drawn (= Scene, Layer, Sprite…)

• Can:

★ Contains other Nodes

★ Schedule periodic callback

★ Execute Actions