SlideShare a Scribd company logo
1 of 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',
null, 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/

More Related Content

Similar to Introduction to HTML5 game development (with Phaser) - Riva

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
 

Similar to Introduction to HTML5 game development (with Phaser) - Riva (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
 
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)
 
VR digest. July 2017
VR digest. July 2017VR digest. July 2017
VR digest. July 2017
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
 
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 ...
 
Intro to HTML5 Game Programming
Intro to HTML5 Game ProgrammingIntro to HTML5 Game Programming
Intro to HTML5 Game Programming
 
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
 
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
 
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
 
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
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.io
 
Snake project report
Snake project reportSnake project report
Snake project report
 
VR digest. December 2017
VR digest. December 2017VR digest. December 2017
VR digest. December 2017
 
The evolution of cloud gaming
The evolution of cloud gamingThe evolution of cloud gaming
The evolution of cloud gaming
 

More from Codemotion

More from Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Introduction to HTML5 game development (with Phaser) - Riva

  • 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', null, 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/