SlideShare una empresa de 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/

Más contenido relacionado

Destacado

Making HTML5 Games with Phaser
Making HTML5 Games with PhaserMaking HTML5 Games with Phaser
Making HTML5 Games with PhaserIndieOutpost
 
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 1Johannes Moser
 
硅谷早期投资趋势
硅谷早期投资趋势硅谷早期投资趋势
硅谷早期投资趋势Rui Ma
 
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 DirectorIndieOutpost
 
Juice up your game feel!
Juice up your game feel!Juice up your game feel!
Juice up your game feel!IndieOutpost
 
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...Pablo Farías Navarro
 
La ecuación de Batman
La ecuación de BatmanLa ecuación de Batman
La ecuación de BatmanJesus Garcia
 
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 FrameworkRyan Chung
 
Phaser Workshop Internet World 2014
Phaser Workshop Internet World 2014Phaser Workshop Internet World 2014
Phaser Workshop Internet World 2014Alvinsight
 
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 AgeCatt Small
 
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 fecejeffers2010
 
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 2015Pablo Farías Navarro
 
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...Himanshu Sharan
 
我的敏捷测试宣言(Agile Testing Manifesto)
我的敏捷测试宣言(Agile Testing Manifesto)我的敏捷测试宣言(Agile Testing Manifesto)
我的敏捷测试宣言(Agile Testing Manifesto)Xudong Yu
 
跨境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...Rui Ma
 

Destacado (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...
 

Similar a Introduction to HTML5 game development (with Phaser)

Scrivere Webapp per Firefox OS - Orru
Scrivere Webapp per Firefox OS - OrruScrivere Webapp per Firefox OS - Orru
Scrivere Webapp per Firefox OS - OrruCodemotion
 
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 LifeDevGAMM Conference
 
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 AzureMarco Parenzan
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12jafar104
 
VR digest. July 2017
VR digest. July 2017VR digest. July 2017
VR digest. July 2017ElifTech
 
Intro to HTML5 Game Programming
Intro to HTML5 Game ProgrammingIntro to HTML5 Game Programming
Intro to HTML5 Game ProgrammingJames Williams
 
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 ...Joseph Labrecque
 
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)David Salz
 
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 FrameworkCsaba Toth
 
Refactoring PHP/Symfony2 apps
Refactoring PHP/Symfony2 appsRefactoring PHP/Symfony2 apps
Refactoring PHP/Symfony2 appsRaul Fraile
 
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 PhaserPablo Farías Navarro
 
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-05Benjamin Nitschke
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.ioSteven Cooper
 
Game Development with Windows Phone 7
Game Development with Windows Phone 7Game Development with Windows Phone 7
Game Development with Windows Phone 7Allan Mangune
 
VR digest. December 2017
VR digest. December 2017VR digest. December 2017
VR digest. December 2017ElifTech
 
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 themesLucas Jellema
 
Snake project report
Snake project reportSnake project report
Snake project reportManju Rajput
 

Similar 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

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Último (20)

Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

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/