SlideShare uma empresa Scribd logo
1 de 29
Introduction to HTML5 game development (with Phaser)
valerio.riva@gmail.com
@ValerioRiva
http://it.linkedin.com/in/valerioriva/
Valerio «Lotti» Riva
Who am I?
• Web developer @ past life
• Game developer @ Interactive Project
• MyGPTeam (http://www.mygpteam.com/)
• MyGPTeam Turbo (http://www.mygpteam.com/turbo/)
• OverVolt: crazy slot cars (coming soon!)
ROME 11-12 april 2014 – Valerio Riva
2
Intro
• Core game development concepts
• Phaser: Desktop and Mobile HTML5 game
framework
• Few useful tools
• Deployment
ROME 11-12 april 2014 – Valerio Riva
3
HTML5 is the new Flash
• No plugin needed!
• Available on all mobile devices
• Low performances on almost
every mobile devices
(especially on Android)
• Flash game frameworks ported
to HTML5 (Flixel -> Phaser!)
ROME 11-12 april 2014 – Valerio Riva
4
To develop an HTML5 game you
need…
• Any OS
• Any editor
• Any web server
Or you can just use Brackets! http://brackets.io/
ROME 11-12 april 2014 – Valerio Riva
5
Phaser (http://phaser.io/)
• Easy to use 2D game framework
• Focused on mobile
• Use pixi.js for WebGL & Canvas rendering
(http://www.pixijs.com/)
• Supports WebAudio & HTML Audio
• Various physics engine supported
• “arcade”: simple AABB physics engine
• p2.js: complete physics engine
(http://schteppe.github.io/p2.js/)
ROME 11-12 april 2014 – Valerio Riva
6
Core Game Development
Concepts
• Loop
• Sprite
• Tilemap
• Collision
• Input
ROME 11-12 april 2014 – Valerio Riva
7
do { game } while (true);
• The hearth of the game
• update loop executes game logic
• Inputs, AI, collisions… your game is computed here!
• rendering loop draws graphic elements to screen
• Phaser game implementation
• Game is a set of states
• Each state has its own loops
• rendering loop is supplied by pixi.js
ROME 11-12 april 2014 – Valerio Riva
8
Phaser game state
Main functions:
• preload: used to load assets
• create: state initialization
• update: the real game loop
• render: called after rendering. Use it for debugging and
post-rendering purposes
• Other function:
• pause: called when the game is paused (on focus loss)
• shutdown: called when leaving a state
• …
ROME 11-12 april 2014 – Valerio Riva
9
Hello Phaser!
ROME 11-12 april 2014 – Valerio Riva
10
Deployment
Web
• Any hosting!
• Game portals
• http://gamepix.com
• http://kongregate.com
• http://armorgames.com
Mobile
• Cordova (Phonegap)
• Intel XDK
• Accelerated webview
• CocoonJS
• Accelerated webview
• API for
Ads, IAP, accelerometer,
etc.
ROME 11-12 april 2014 –
Valerio Riva
11
Sprite
“In computer graphics, a sprite is a two-
dimensional image or animation that is
integrated into a larger scene.”
• Has a set of coordinates
and sizes
• Can be animated with
sequential drawings
• Main actor of a 2D game
ROME 11-12 april 2014 – Valerio Riva
12
• Be created
• Scale
• Rotate
• Moves
• Animate
• Have physic body
for collisions
• and much more!
var s = game.add.sprite(x,y, "image");
s.scale.setTo(0.75,0.75);
s.angle=180 / s.rotation=3.141
s.x += 10; s.y -= 10;
s.animations.play("walk",fps);
game.physics.arcade.enable(s);
ROME 11-12 april 2014 – Valerio Riva
What sprites can do
ROME 11-12 april 2014 –
Valerio Riva
13
Group of sprites
• Use it as z-ordered layer
• Use it for fast pooling and object recycling too
• Can apply transformation to all sprites of the group
• Can call methods on all sprites of the group
var group = game.add.group();
var sprite = group.create(x, y, 'image');
group.x += 100;
group.callAll('kill');
var zombie = group.getFirstExists(false);
zombie.revive(); //cured!
ROME 11-12 april 2014 – Valerio Riva
14
Tilesprite
“A tilesprite is a sprite that has a repeating texture.”
var tilesprite =
game.add.tileSprite(0, 0, 32, 64, 'image');
• texture can be scrolled
tilesprite.tilePosition.setTo(10,20);
• texture can be scaled
tilesprite.tileScale.setTo(1.5,1.5);
ROME 11-12 april 2014 – Valerio Riva
15
Tilemap
ROME 11-12 april 2014 – Valerio Riva
16
Tilemap
A tilemap is a map composed by a fixed number of
same sized sprites (tiles)
• Each tile can have different behavior
• Used to create platform and map based games
• Can be orthogonal or isometric
• Easy to create with Tiled
(http://www.mapeditor.org/)
ROME 11-12 april 2014 – Valerio Riva
17
Tilemap
function preload() {
game.load.tilemap('codem', 'tilemap/codem.json', n
ull, Phaser.Tilemap.TILED_JSON);
game.load.image('block', 'sprites/block.gif');
}
function create() {
map = game.add.tilemap("codem");
map.addTilesetImage("block");
map.setCollisionByExclusion([]);
layer = map.createLayer("codemotion");
layer.resizeWorld();
}
ROME 11-12 april 2014 – Valerio Riva
18
Collision
“A collision is an instance of one moving object touching
another.”
• Both object must have a “body” (collider)
• Object can be a sprite or a tilemap or even a group!
• A body can be a rectangle, a circle or a polygon
• Bodies can have a lot of properties
(mass, gravity, velocity, material, …)
• Last two statements depends on what physics engine
you are using.
• More complex is the engine, more computation is
needed. Choose wisely!
ROME 11-12 april 2014 – Valerio Riva
19
Collision
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
sprite = game.add.sprite(0, 0, 'image');
game.physics.enable(sprite, Phaser.Physics.ARCADE);
sprite.body.collideWorldBounds = true;
sprite.body.bounce.set(1);
}
function update() {
game.physics.arcade.collide(sprite, [tilemap, group],
function(sprite, other) { … });
}
ROME 11-12 april 2014 – Valerio Riva
20
Input
Phaser supports natively
• Keyboard
• Mouse
• Multi-touch
• Gamepads (up to four, each one with 10 axis and
16 buttons)
• Supports even Xbox 360 gamepad! (button
mapping depends on browser : )
ROME 11-12 april 2014 – Valerio Riva
21
Input: Keyboard
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
ufo.y -= 10;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
ufo.y += 10;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ufo.x -= 10;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
ufo.x += 10;
}
}
ROME 11-12 april 2014 – Valerio Riva
22
Input: Mouse
if (game.input.mousePointer.isDown) {
if (game.input.mousePointer.x < game.width*0.5) {
clickOnLeft = true;
}
else if (game.input.mousePointer.x > game.width*0.5) {
clickOnRight = true;
}
if (game.input.mousePointer.y < game.height*0.5) {
clickOnTop = true;
}
}
• Swap mousePointer with activePointer to capture
any active pointer (works with mouse and touch
inputs)
ROME 11-12 april 2014 – Valerio Riva
23
Input: Multi-touch
• Supports 10 pointers (= fingers)!
• Two pointers are already available
• Add another pointer
game.input.addPointer();
• Read different pointers
game.input.pointer3; or game.input.pointer4;
ROME 11-12 april 2014 – Valerio Riva
24
Input: Gamepad
function create() {
game.input.gamepad.start();
pad1 = game.input.gamepad.pad1;
}
function update() {
if (game.input.gamepad.supported
&& game.input.gamepad.active
&& pad1.connected) {
//play with gamepad!
if (pad1.isDown(Phaser.Gamepad.XBOX360_DPAD_LEFT)) { … }
if (pad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)) { … }
if (pad1.justPressed(Phaser.Gamepad.XBOX360_A)) { … }
}
else {
//play with boring keyboard!
}
}
ROME 11-12 april 2014 – Valerio Riva
25
Dissecting the mummy
ROME 11-12 april 2014 – Valerio Riva
26
Want more?
• Take a look to another example that implements P2
physics engine (http://github.com/Lotti/phaserTut)
• Phaser examples (http://examples.phaser.io/)
• Phaser docs (http://docs.phaser.io/)
ROME 11-12 april 2014 – Valerio Riva
27
Resources & Links
• The mummy game
• P2 physics engine example
• Phaser’s forum
• http://docs.phaser.io
• http://examples.phaser.io
• http://html5gameengine.com
• http://brackets.io
• http://www.pixijs.com
• http://schteppe.github.io/p2.js
• http://www.mapeditor.org
• http://xdk-software.intel.com
• https://www.ludei.com/cocoonjs
• https://cordova.apache.org
• http://phonegap.com
ROME 11-12 april 2014 –
Valerio Riva
28
Thank you!
Any Questions?
ROME 11-12 april 2014 – Valerio Riva
29
valerio.riva@gmail.com
@ValerioRiva
http://it.linkedin.com/in/valerioriva/

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL Applications
 
O que há de incrível sobre o Flutter
O que há de incrível sobre o FlutterO que há de incrível sobre o Flutter
O que há de incrível sobre o Flutter
 
Prometheus
PrometheusPrometheus
Prometheus
 
The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern Matching
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
 
Reitit - Clojure/North 2019
Reitit - Clojure/North 2019Reitit - Clojure/North 2019
Reitit - Clojure/North 2019
 
JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainers
 
De Java 8 a Java 17
De Java 8 a Java 17De Java 8 a Java 17
De Java 8 a Java 17
 
Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
A Deep Dive into JSON-LD and Hydra
A Deep Dive into JSON-LD and HydraA Deep Dive into JSON-LD and Hydra
A Deep Dive into JSON-LD and Hydra
 
Advanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scripts
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Monitoring with Prometheus
Monitoring with PrometheusMonitoring with Prometheus
Monitoring with Prometheus
 
Atomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas HunterAtomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas Hunter
 
Terraform
TerraformTerraform
Terraform
 
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
 
[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse
 

Destaque

La ecuación de Batman
La ecuación de BatmanLa ecuación de Batman
La ecuación de Batman
Jesus Garcia
 
Lasertron lt 12 vs zone nexus fec
Lasertron lt 12 vs zone nexus fecLasertron lt 12 vs zone nexus fec
Lasertron lt 12 vs zone nexus fec
ejeffers2010
 

Destaque (20)

Phaser presentation
Phaser presentationPhaser presentation
Phaser presentation
 
Making HTML5 Games with Phaser
Making HTML5 Games with PhaserMaking HTML5 Games with Phaser
Making HTML5 Games with Phaser
 
Introduction to Phaser.js
Introduction to Phaser.jsIntroduction to Phaser.js
Introduction to Phaser.js
 
VlbgWebDev Mai 2015 - Game Design PT 1
VlbgWebDev Mai 2015 - Game Design PT 1VlbgWebDev Mai 2015 - Game Design PT 1
VlbgWebDev Mai 2015 - Game Design PT 1
 
硅谷早期投资趋势
硅谷早期投资趋势硅谷早期投资趋势
硅谷早期投资趋势
 
Keep your game in the fun zone - Designing an AI Director
Keep your game in the fun zone - Designing an AI DirectorKeep your game in the fun zone - Designing an AI Director
Keep your game in the fun zone - Designing an AI Director
 
Juice up your game feel!
Juice up your game feel!Juice up your game feel!
Juice up your game feel!
 
HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...
HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...
HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...
 
La ecuación de Batman
La ecuación de BatmanLa ecuación de Batman
La ecuación de Batman
 
Flappy Bird Game Dev by Phaser Framework
Flappy Bird Game Dev by Phaser FrameworkFlappy Bird Game Dev by Phaser Framework
Flappy Bird Game Dev by Phaser Framework
 
Html5 game development
Html5 game developmentHtml5 game development
Html5 game development
 
Phaser Workshop Internet World 2014
Phaser Workshop Internet World 2014Phaser Workshop Internet World 2014
Phaser Workshop Internet World 2014
 
Making Native Browser Games in The Modern Age
Making Native Browser Games in The Modern AgeMaking Native Browser Games in The Modern Age
Making Native Browser Games in The Modern Age
 
Marketing 360 - 2011
Marketing 360 - 2011Marketing 360 - 2011
Marketing 360 - 2011
 
Lasertron lt 12 vs zone nexus fec
Lasertron lt 12 vs zone nexus fecLasertron lt 12 vs zone nexus fec
Lasertron lt 12 vs zone nexus fec
 
HTML5 Game Development frameworks overview
HTML5 Game Development frameworks overviewHTML5 Game Development frameworks overview
HTML5 Game Development frameworks overview
 
HTML5 Mobile Game Development - Brisbane Game Technology Meetup 2015
HTML5 Mobile Game Development - Brisbane Game Technology Meetup 2015HTML5 Mobile Game Development - Brisbane Game Technology Meetup 2015
HTML5 Mobile Game Development - Brisbane Game Technology Meetup 2015
 
Multi-platform Compatibility of HTML5 by developing simple HTML5 based game(M...
Multi-platform Compatibility of HTML5 by developing simple HTML5 based game(M...Multi-platform Compatibility of HTML5 by developing simple HTML5 based game(M...
Multi-platform Compatibility of HTML5 by developing simple HTML5 based game(M...
 
我的敏捷测试宣言(Agile Testing Manifesto)
我的敏捷测试宣言(Agile Testing Manifesto)我的敏捷测试宣言(Agile Testing Manifesto)
我的敏捷测试宣言(Agile Testing Manifesto)
 
跨境10年 - The Next Decade of US China Crossborder Early Stage Tech Venture Inve...
跨境10年 - The Next Decade of US China Crossborder Early Stage Tech Venture Inve...跨境10年 - The Next Decade of US China Crossborder Early Stage Tech Venture Inve...
跨境10年 - The Next Decade of US China Crossborder Early Stage Tech Venture Inve...
 

Semelhante a Introduction to HTML5 game development (with Phaser)

Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
jafar104
 
Game Development with Windows Phone 7
Game Development with Windows Phone 7Game Development with Windows Phone 7
Game Development with Windows Phone 7
Allan Mangune
 

Semelhante a Introduction to HTML5 game development (with Phaser) (20)

Scrivere Webapp per Firefox OS - Orru
Scrivere Webapp per Firefox OS - OrruScrivere Webapp per Firefox OS - Orru
Scrivere Webapp per Firefox OS - Orru
 
Bigpoint: Game of Thrones: Bringing Westeros to Life
Bigpoint: Game of Thrones: Bringing Westeros to LifeBigpoint: Game of Thrones: Bringing Westeros to Life
Bigpoint: Game of Thrones: Bringing Westeros to Life
 
Ferguson VR Hackathon - May 6, 2017
Ferguson VR Hackathon - May 6, 2017Ferguson VR Hackathon - May 6, 2017
Ferguson VR Hackathon - May 6, 2017
 
Build a serverless distributed Pong game with Azure
Build a serverless distributed Pong game with AzureBuild a serverless distributed Pong game with Azure
Build a serverless distributed Pong game with Azure
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
 
VR digest. July 2017
VR digest. July 2017VR digest. July 2017
VR digest. July 2017
 
Intro to HTML5 Game Programming
Intro to HTML5 Game ProgrammingIntro to HTML5 Game Programming
Intro to HTML5 Game Programming
 
What’s Going On with the Adobe® Flash® Platform and why it is still Relevant ...
What’s Going On with the Adobe® Flash® Platform and why it is still Relevant ...What’s Going On with the Adobe® Flash® Platform and why it is still Relevant ...
What’s Going On with the Adobe® Flash® Platform and why it is still Relevant ...
 
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
 
Developing Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay FrameworkDeveloping Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay Framework
 
XNA L01–Introduction
XNA L01–IntroductionXNA L01–Introduction
XNA L01–Introduction
 
Refactoring PHP/Symfony2 apps
Refactoring PHP/Symfony2 appsRefactoring PHP/Symfony2 apps
Refactoring PHP/Symfony2 apps
 
Teacher Training Workshop - Game Development with Phaser
Teacher Training Workshop  - Game Development with PhaserTeacher Training Workshop  - Game Development with Phaser
Teacher Training Workshop - Game Development with Phaser
 
Delta Engine Multiplatform Development Presentation 2011-05
Delta Engine Multiplatform Development Presentation 2011-05Delta Engine Multiplatform Development Presentation 2011-05
Delta Engine Multiplatform Development Presentation 2011-05
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.io
 
Game Development with Windows Phone 7
Game Development with Windows Phone 7Game Development with Windows Phone 7
Game Development with Windows Phone 7
 
Java8 launch at AMIS Services / First8
Java8 launch at AMIS Services / First8Java8 launch at AMIS Services / First8
Java8 launch at AMIS Services / First8
 
VR digest. December 2017
VR digest. December 2017VR digest. December 2017
VR digest. December 2017
 
Java 8 Launch Event - Past, Present and Future of Java and Java 8 key themes
Java 8 Launch Event - Past, Present and Future of Java and Java 8 key themesJava 8 Launch Event - Past, Present and Future of Java and Java 8 key themes
Java 8 Launch Event - Past, Present and Future of Java and Java 8 key themes
 
Snake project report
Snake project reportSnake project report
Snake project report
 

Último

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 

Introduction to HTML5 game development (with Phaser)

  • 1. Introduction to HTML5 game development (with Phaser) valerio.riva@gmail.com @ValerioRiva http://it.linkedin.com/in/valerioriva/ Valerio «Lotti» Riva
  • 2. Who am I? • Web developer @ past life • Game developer @ Interactive Project • MyGPTeam (http://www.mygpteam.com/) • MyGPTeam Turbo (http://www.mygpteam.com/turbo/) • OverVolt: crazy slot cars (coming soon!) ROME 11-12 april 2014 – Valerio Riva 2
  • 3. Intro • Core game development concepts • Phaser: Desktop and Mobile HTML5 game framework • Few useful tools • Deployment ROME 11-12 april 2014 – Valerio Riva 3
  • 4. HTML5 is the new Flash • No plugin needed! • Available on all mobile devices • Low performances on almost every mobile devices (especially on Android) • Flash game frameworks ported to HTML5 (Flixel -> Phaser!) ROME 11-12 april 2014 – Valerio Riva 4
  • 5. To develop an HTML5 game you need… • Any OS • Any editor • Any web server Or you can just use Brackets! http://brackets.io/ ROME 11-12 april 2014 – Valerio Riva 5
  • 6. Phaser (http://phaser.io/) • Easy to use 2D game framework • Focused on mobile • Use pixi.js for WebGL & Canvas rendering (http://www.pixijs.com/) • Supports WebAudio & HTML Audio • Various physics engine supported • “arcade”: simple AABB physics engine • p2.js: complete physics engine (http://schteppe.github.io/p2.js/) ROME 11-12 april 2014 – Valerio Riva 6
  • 7. Core Game Development Concepts • Loop • Sprite • Tilemap • Collision • Input ROME 11-12 april 2014 – Valerio Riva 7
  • 8. do { game } while (true); • The hearth of the game • update loop executes game logic • Inputs, AI, collisions… your game is computed here! • rendering loop draws graphic elements to screen • Phaser game implementation • Game is a set of states • Each state has its own loops • rendering loop is supplied by pixi.js ROME 11-12 april 2014 – Valerio Riva 8
  • 9. Phaser game state Main functions: • preload: used to load assets • create: state initialization • update: the real game loop • render: called after rendering. Use it for debugging and post-rendering purposes • Other function: • pause: called when the game is paused (on focus loss) • shutdown: called when leaving a state • … ROME 11-12 april 2014 – Valerio Riva 9
  • 10. Hello Phaser! ROME 11-12 april 2014 – Valerio Riva 10
  • 11. Deployment Web • Any hosting! • Game portals • http://gamepix.com • http://kongregate.com • http://armorgames.com Mobile • Cordova (Phonegap) • Intel XDK • Accelerated webview • CocoonJS • Accelerated webview • API for Ads, IAP, accelerometer, etc. ROME 11-12 april 2014 – Valerio Riva 11
  • 12. Sprite “In computer graphics, a sprite is a two- dimensional image or animation that is integrated into a larger scene.” • Has a set of coordinates and sizes • Can be animated with sequential drawings • Main actor of a 2D game ROME 11-12 april 2014 – Valerio Riva 12
  • 13. • Be created • Scale • Rotate • Moves • Animate • Have physic body for collisions • and much more! var s = game.add.sprite(x,y, "image"); s.scale.setTo(0.75,0.75); s.angle=180 / s.rotation=3.141 s.x += 10; s.y -= 10; s.animations.play("walk",fps); game.physics.arcade.enable(s); ROME 11-12 april 2014 – Valerio Riva What sprites can do ROME 11-12 april 2014 – Valerio Riva 13
  • 14. Group of sprites • Use it as z-ordered layer • Use it for fast pooling and object recycling too • Can apply transformation to all sprites of the group • Can call methods on all sprites of the group var group = game.add.group(); var sprite = group.create(x, y, 'image'); group.x += 100; group.callAll('kill'); var zombie = group.getFirstExists(false); zombie.revive(); //cured! ROME 11-12 april 2014 – Valerio Riva 14
  • 15. Tilesprite “A tilesprite is a sprite that has a repeating texture.” var tilesprite = game.add.tileSprite(0, 0, 32, 64, 'image'); • texture can be scrolled tilesprite.tilePosition.setTo(10,20); • texture can be scaled tilesprite.tileScale.setTo(1.5,1.5); ROME 11-12 april 2014 – Valerio Riva 15
  • 16. Tilemap ROME 11-12 april 2014 – Valerio Riva 16
  • 17. Tilemap A tilemap is a map composed by a fixed number of same sized sprites (tiles) • Each tile can have different behavior • Used to create platform and map based games • Can be orthogonal or isometric • Easy to create with Tiled (http://www.mapeditor.org/) ROME 11-12 april 2014 – Valerio Riva 17
  • 18. Tilemap function preload() { game.load.tilemap('codem', 'tilemap/codem.json', n ull, Phaser.Tilemap.TILED_JSON); game.load.image('block', 'sprites/block.gif'); } function create() { map = game.add.tilemap("codem"); map.addTilesetImage("block"); map.setCollisionByExclusion([]); layer = map.createLayer("codemotion"); layer.resizeWorld(); } ROME 11-12 april 2014 – Valerio Riva 18
  • 19. Collision “A collision is an instance of one moving object touching another.” • Both object must have a “body” (collider) • Object can be a sprite or a tilemap or even a group! • A body can be a rectangle, a circle or a polygon • Bodies can have a lot of properties (mass, gravity, velocity, material, …) • Last two statements depends on what physics engine you are using. • More complex is the engine, more computation is needed. Choose wisely! ROME 11-12 april 2014 – Valerio Riva 19
  • 20. Collision function create() { game.physics.startSystem(Phaser.Physics.ARCADE); sprite = game.add.sprite(0, 0, 'image'); game.physics.enable(sprite, Phaser.Physics.ARCADE); sprite.body.collideWorldBounds = true; sprite.body.bounce.set(1); } function update() { game.physics.arcade.collide(sprite, [tilemap, group], function(sprite, other) { … }); } ROME 11-12 april 2014 – Valerio Riva 20
  • 21. Input Phaser supports natively • Keyboard • Mouse • Multi-touch • Gamepads (up to four, each one with 10 axis and 16 buttons) • Supports even Xbox 360 gamepad! (button mapping depends on browser : ) ROME 11-12 april 2014 – Valerio Riva 21
  • 22. Input: Keyboard function update() { if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ufo.y -= 10; } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ufo.y += 10; } if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ufo.x -= 10; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ufo.x += 10; } } ROME 11-12 april 2014 – Valerio Riva 22
  • 23. Input: Mouse if (game.input.mousePointer.isDown) { if (game.input.mousePointer.x < game.width*0.5) { clickOnLeft = true; } else if (game.input.mousePointer.x > game.width*0.5) { clickOnRight = true; } if (game.input.mousePointer.y < game.height*0.5) { clickOnTop = true; } } • Swap mousePointer with activePointer to capture any active pointer (works with mouse and touch inputs) ROME 11-12 april 2014 – Valerio Riva 23
  • 24. Input: Multi-touch • Supports 10 pointers (= fingers)! • Two pointers are already available • Add another pointer game.input.addPointer(); • Read different pointers game.input.pointer3; or game.input.pointer4; ROME 11-12 april 2014 – Valerio Riva 24
  • 25. Input: Gamepad function create() { game.input.gamepad.start(); pad1 = game.input.gamepad.pad1; } function update() { if (game.input.gamepad.supported && game.input.gamepad.active && pad1.connected) { //play with gamepad! if (pad1.isDown(Phaser.Gamepad.XBOX360_DPAD_LEFT)) { … } if (pad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X)) { … } if (pad1.justPressed(Phaser.Gamepad.XBOX360_A)) { … } } else { //play with boring keyboard! } } ROME 11-12 april 2014 – Valerio Riva 25
  • 26. Dissecting the mummy ROME 11-12 april 2014 – Valerio Riva 26
  • 27. Want more? • Take a look to another example that implements P2 physics engine (http://github.com/Lotti/phaserTut) • Phaser examples (http://examples.phaser.io/) • Phaser docs (http://docs.phaser.io/) ROME 11-12 april 2014 – Valerio Riva 27
  • 28. Resources & Links • The mummy game • P2 physics engine example • Phaser’s forum • http://docs.phaser.io • http://examples.phaser.io • http://html5gameengine.com • http://brackets.io • http://www.pixijs.com • http://schteppe.github.io/p2.js • http://www.mapeditor.org • http://xdk-software.intel.com • https://www.ludei.com/cocoonjs • https://cordova.apache.org • http://phonegap.com ROME 11-12 april 2014 – Valerio Riva 28
  • 29. Thank you! Any Questions? ROME 11-12 april 2014 – Valerio Riva 29 valerio.riva@gmail.com @ValerioRiva http://it.linkedin.com/in/valerioriva/