63
Build a Game in 60 minutes PeopleSpace, Irvine CA 24 May 2016

Build a Game in 60 minutes

Embed Size (px)

Citation preview

Page 1: Build a Game in 60 minutes

Build a Game in 60 minutesPeopleSpace, Irvine CA 24 May 2016

Page 2: Build a Game in 60 minutes
Page 3: Build a Game in 60 minutes

Code and Slides

http://www.slideshare.net/rockncoder/build-a-game-in-60-minutes

https://github.com/Rockncoder/oldschool

Page 4: Build a Game in 60 minutes

Troy MilesTroy Miles

Over 37 years of programming experience

Speaker and author

Author of jQuery Essentials

[email protected]

@therockncoder

Page 5: Build a Game in 60 minutes
Page 6: Build a Game in 60 minutes

Cocos2d-x: Introduction

Page 7: Build a Game in 60 minutes

What is Cocos2d-x?

Open source game engine under MIT license

It is optimized for 2D graphics using OpenGL

Used by more than 400,000 developers worldwide

Page 8: Build a Game in 60 minutes

History

2008 Ricardo Quesada in Argentina creates Cocos2d

Ported to iPhone with the opening of the iPhone App Store

2010 Zhe Wang in China forks it creating Cocos2d-x

2013 Ricardo joins Cocos2d-x team

12 May 2016 version 3.11 released

Page 9: Build a Game in 60 minutes

Target Platforms

Android

iOS (iPhone + iPad)

Mac OS X

Windows Phone 8

Windows 7

Page 10: Build a Game in 60 minutes

Development Platforms

Visual Studio 2012+ (Windows)

Xcode 4.6+ (Mac)

CMake 2.6+ (Ubuntu)

All platforms need Python v2.7.x (not 3!)

Page 11: Build a Game in 60 minutes

Development Languages

C++

Lua

JavaScript (all except WP8)

Page 12: Build a Game in 60 minutes

Why JavaScript?

Arguably the most popular programming language

It is universal

It is fast

Way easier to learn than C++

Page 13: Build a Game in 60 minutes

Mandatory Tools

iOS / Mac OS X apps require Xcode and a Mac

Windows / WP8 apps require VS and a PC

Page 14: Build a Game in 60 minutes

Titles using Cocos2d-x

Page 15: Build a Game in 60 minutes

Text

Avengers AllianceMarvel Entertainment

Page 16: Build a Game in 60 minutes

Text

Family Guy: The Quest for StuffTinyCo, Inc.

Page 17: Build a Game in 60 minutes

Diamond DashWooga

Page 18: Build a Game in 60 minutes

Star Wars: Tiny Death StarLucasArts

Page 19: Build a Game in 60 minutes

BADLANDFrogmind

Page 20: Build a Game in 60 minutes
Page 21: Build a Game in 60 minutes

Key Points

Cocos2d has been around since 2008

Cocos2d-x uses C++ for speed

A lot of big name titles use it

It has always been free and always will be

Page 22: Build a Game in 60 minutes

Cocos2d-x: Installation

Page 23: Build a Game in 60 minutes

Keep in mind…

I am using a Mac, but Cocos2D-x is cross platform

Everything will work on Windows and Linux

Page 24: Build a Game in 60 minutes

Mac Development

Python 2.7.x

Apple Xcode

(Jetbrains’ AppCode)

Page 25: Build a Game in 60 minutes

Windows Development

Python 2.7.x

Visual Studio 2012+

Windows Phone SDK 8

Page 26: Build a Game in 60 minutes

cocos2d-x.org

Tutorials

Forum

Blog

Downloads

Page 27: Build a Game in 60 minutes

Download

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

Under the column, Cocos2d-x,

Click, “DOWNLOAD V3.11”

Unzip it

Page 28: Build a Game in 60 minutes

Installation

From terminal or command prompt

cd to the root of the directory

setup.py

(will modify your path and other env variables)

open the project for your environment

Page 29: Build a Game in 60 minutes

Key Points

Installing cocos2d-x is pretty easy

Everything is done from the command line

Page 30: Build a Game in 60 minutes

Cocos2d-x: Feature Overview

Page 31: Build a Game in 60 minutes
Page 32: Build a Game in 60 minutes

JavaScript

Uses Mozilla’s SpiderMonkey JS Engine v33

Released 14 Oct 2014

Same engine used in FireFox 33

Support a lot of ES6 features

(except templates strings)

Page 33: Build a Game in 60 minutes

Widgets

Button

CheckBox

ListView

Slider

TextField

Page 34: Build a Game in 60 minutes

Audio

Sound effects

Background music

CocosDenshion library (Open AL)

Support audio is platform dependent

Page 35: Build a Game in 60 minutes

PhysicsChipmunk2D

Portable 2-dimensional real-time rigid body physics engine

Written in C99 by Scott Lembcke

Box2d

Free open source 2-dimensional physics simulator engine

Written in C++ by Erin Catto

Published under the zlib license

Page 36: Build a Game in 60 minutes

Network

HTTP + SSL

WebSocket API

XMLHttpRequest API

Page 37: Build a Game in 60 minutes

User Input

Touch/Accelerometer on mobile devices

Touch/Mouse/Keyboard on desktop

Game controller support

Page 38: Build a Game in 60 minutes

2D GraphicsTransitions between scenes

Sprites and Sprite Sheets

Effects: Lens, Ripple, Waves, Liquid, etc.

Transformation Actions: Move, Rotate, Scale, Fade, Tint, etc.

Composable actions: Sequence, Spawn, Repeat, Reverse

Page 39: Build a Game in 60 minutes

2D Graphics

Ease Actions: Exp, Sin, Cubic, Elastic, etc.

Misc actions: CallFunc, OrbitCamera, Follow, Tween

Particle system

Skeleton Animations: Spine and Adobe DragonBone

Fast font rendering using Fixed and Variable width fonts

Page 40: Build a Game in 60 minutes

2D GraphicsTrueType fonts

Tile Map support: Orthogonal, Isometric and Hexagonal

Parallax scrolling

Motion Streak

Render To Texture

Page 41: Build a Game in 60 minutes

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: Build a Game in 60 minutes

Let’s make a game

Page 43: Build a Game in 60 minutes

Cocos command optionsnew - creates a new game

run - compile, deploy, and run on game on target

deploy - deploy game to target

compile - compiles game

luacompile - minifies Lua files and compiles

jscompile - minifies JS files and compiles

Page 44: Build a Game in 60 minutes

Cocos command options

-h, —help - Shows the help

-v, —version - Shows the current version

Page 45: Build a Game in 60 minutes

Creating a new game

Open the cmd window

Validate that cocos is in your path, cocos <enter>

cocos new gamename -p com.company.name -l js

Page 46: Build a Game in 60 minutes

new command explained

MyGame: name of your project

-p com.mycompany.mygame: package name

-l js: programming language used for the project, valid values are: cpp, lua, and js

Page 47: Build a Game in 60 minutes

Directory Structure

Classes

cocos2d

Resources

Platform directories

Page 48: Build a Game in 60 minutes

Class Directory

AppDelegate initializes cocos2d-x

HelloWorldScene is where your game begins

Page 49: Build a Game in 60 minutes

Hello World

Cocos2D-x ships as source code

Build it to compile the libraries

Page 50: Build a Game in 60 minutes

Bootup on Mac

launches from main.cpp

calls AppDelegate.cpp

(starts up Cocos2D-x)

calls main.js

(launches your scene)

Page 51: Build a Game in 60 minutes

Graphics Diagnostics

configured in project.json

82 <-- number of draw calls

0.016 <-- time it took to render the frame

60.0 <-- frames per second

Page 52: Build a Game in 60 minutes

Don’t forget

Add JavaScript files to the project.json

Add resources (images/sound/music) to resources.js

Forgetting to add them is a very common bug

Page 53: Build a Game in 60 minutes

Lexicon

Director

Node

Scene

Layer

Sprite

Action

Particle

Event

Page 54: Build a Game in 60 minutes

Adding Scenes

Scenes are actually derived from the Layer class

Add scene for main, game, pause, end game

Add colors to scenes

Add transitions

Page 55: Build a Game in 60 minutes

The Game Loop

The central component of any game

Allows game to run smoothly regardless of user input

Allows game to run at same speed regardless of machine

Page 56: Build a Game in 60 minutes

Game Loop Reality

In the scene init add, this.scheduleUpdate()

Add an update method, HelloWorld::update(float dt)

The update method should be as fast as possible

Page 57: Build a Game in 60 minutes

Steps

Add a background

Add a hero

Move the hero

Detect touches

Fire bullets

Add enemy

Animate enemy

Detect collision

Give points

Detect end of game

Page 58: Build a Game in 60 minutes

Steps

Adding sound

Adding music

Adding scenes

Page 59: Build a Game in 60 minutes

Resourceshttp://www.nosoapradio.us/

http://www.freesound.org/

http://spritedatabase.net/

http://opengameart.org/

http://www.lostgarden.com/search/label/free%20game%20graphics

Page 60: Build a Game in 60 minutes

More resources

http://www.spriters-resource.com/

https://github.com/cocos2d/cocos2d-js-tests/tree/master/games

https://github.com/dalinaum/chukong-cocos-docs/tree/master/tutorial/framework/html5/parkour-game-with-javascript-v3.0

Page 61: Build a Game in 60 minutes

Code and Slides

http://www.slideshare.net/rockncoder/build-a-game-in-60-minutes

https://github.com/Rockncoder/oldschool

Page 62: Build a Game in 60 minutes

Summary

Cocos2d-x is a free open source game engine

It supports Android, iOS, Windows and Mac

Page 63: Build a Game in 60 minutes

Questions?