Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... ·...

50
Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October 1, 2009

Transcript of Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... ·...

Page 1: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Introduction to 2d Game Programming Using cocos2d

Serban PorumbescuThursday, October 1, 2009

Page 2: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

www.hiddenelephant.com

Thursday, October 1, 2009

Page 3: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Overview

• Why cocos2d?

• Beginner Hurdles

• cocos2d Basics

• cocos2d Specifics

• Samples and Tests

• Resources

Thursday, October 1, 2009

Page 4: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Why cocos2d?

• Well over 200 games shipped

• Great licensing

• Lots of features

• Extremely active community

• What’s your business?

Thursday, October 1, 2009

Page 5: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Beginner Hurdles

Thursday, October 1, 2009

Page 6: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Beginner Hurdles

• Objective-C and Memory

• Setting Up a cocos2d Project

• Running Samples and Tests

• Understanding Tests

Thursday, October 1, 2009

Page 9: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

cocos2d Project Setup

• Super easy ... now

• sudo ./install_template.sh

Thursday, October 1, 2009

Page 10: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 11: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 12: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 13: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Running Samples & Tests

• Wonderful source of examples that people seem to overlook

• Once noticed, folks have issues running

Thursday, October 1, 2009

Page 14: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 15: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Running Samples & Tests

• Where are they and how do we run?

Thursday, October 1, 2009

Page 16: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 17: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 18: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Running Samples & Tests

• Make sure to set both the “Active Target” and the “Active Executable”

Thursday, October 1, 2009

Page 19: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 20: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 21: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Tests

• Not games

• Meant to exercise some specific functionality

• Useful for figuring stuff out

Thursday, October 1, 2009

Page 22: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Tests

• Structured very similarly

• Some base test class

• Instantiate new test by advancing through NSStrings using NSClassFromString

Thursday, October 1, 2009

Page 23: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Tests

• Let’s look at AtlasSpriteTest and EaseActionsTest

Thursday, October 1, 2009

Page 24: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

cocos2d Basics

Thursday, October 1, 2009

Page 25: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

cocos2d Basics

• Game has Scenes

• Each Scene has some number of Layers

• Layers capture user interaction and contain sprites

• Director manages the scenes

Thursday, October 1, 2009

Page 26: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Scenes

• Screens in your game

• Can almost think of them as separate apps

Thursday, October 1, 2009

Page 27: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Layers

• Take up the entire screen

• Setup to handle touch and accelerometer

• Can contain other layers and sprites (and other stuff)

Thursday, October 1, 2009

Page 28: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Sprites

Thursday, October 1, 2009

Page 29: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Director

• Manages moving between Scenes

• Pausing and running Scenes

• Sets up OpenGL ES

• Layer asks Director to move on

Thursday, October 1, 2009

Page 30: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 31: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

cocos2d Specifics

Thursday, October 1, 2009

Page 32: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thursday, October 1, 2009

Page 33: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Important Classes• CocosNode

• Scene

• Layer

• Director

• AtlasSprite

• AtlasSpriteManager

Thursday, October 1, 2009

Page 34: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

CocosNode

Thursday, October 1, 2009

Page 35: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

CocosNode

• Lots of properties

• position, scale, camera, OpenGL z position, children

• Most objects in cocos2d inherit from CocosNode

Thursday, October 1, 2009

Page 36: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Scene

Thursday, October 1, 2009

Page 37: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Layer

Thursday, October 1, 2009

Page 38: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Director(s)

Thursday, October 1, 2009

Page 39: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

AtlasSprite

Thursday, October 1, 2009

Page 40: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

AtlasSpriteManager

Thursday, October 1, 2009

Page 41: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Sprite vs. AtlasSprite

Thursday, October 1, 2009

Page 42: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Sprites

Thursday, October 1, 2009

Page 43: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

AtlasSprite

Thursday, October 1, 2009

Page 44: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Sprite vs. AtlasSprite

• In general, don’t use Sprites

• AtlasSprites way faster

• It’s all about the OpenGL ES

Thursday, October 1, 2009

Page 45: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Samples and Tests

Thursday, October 1, 2009

Page 46: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Resources

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

Thursday, October 1, 2009

Page 47: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Resources

Wiki: http://www.cocos2d-iphone.org/wiki/doku.php/

Thursday, October 1, 2009

Page 48: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Resources

Forums: http://www.cocos2d-iphone.org/forum/

Thursday, October 1, 2009

Page 49: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

iPhoneGameJam.com

Thursday, October 1, 2009

Page 50: Introduction to 2d Game Programming Using cocos2dhiddenelephantblog.dreamhosters.com/blog/wp... · Introduction to 2d Game Programming Using cocos2d Serban Porumbescu Thursday, October

Thanks!

Thursday, October 1, 2009