Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Phaser workshop
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Alvin Berthelot
April 07, 2016
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Phaser workshop
Alvin Berthelot
April 07, 2016
More Decks by Alvin Berthelot
See All by Alvin Berthelot
Sass, pratique tout de suite
alvinberthelot
0
120
css-tooling
alvinberthelot
0
120
Sass workshop
alvinberthelot
0
160
Devoxx15 - Let's sketch together
alvinberthelot
1
140
Let's sketch together
alvinberthelot
0
1.7k
Other Decks in Programming
See All in Programming
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
270
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
110
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
320
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.3k
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
460
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
200
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
380
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
5.8k
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
520
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
410
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Crafting Experiences
bethany
1
360
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Six Lessons from altMBA
skipperchong
29
4.5k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Tell your own story through comics
letsgokoyo
1
1.1k
Building Adaptive Systems
keathley
44
3.2k
Transcript
Code & Play
Hello Pierre CHABILAND @PierreChabiland casusludi.com Alvin BERTHELOT @alvinberthelot webyousoon.com
Our goals Coder un jeu web Découvrir Phaser Se faire
plaisir
Progress 1. Présentation Phaser 2. Présentation du code/Git 3. Concepts
puis réalisation du jeu “Step by step” 4. Temps d’expérimentation et de fun
The game to build ARKANOID
Phaser
Phaser Framework de jeu 2D en HTML5/JS pour le web
mobile et desktop Exploite WebGL et Canvas (se base sur PIXI.JS pour le rendu d’affichage) Accent mis sur les performances web mobiles
Features - Sprites / Animation - Particules - Moteurs physique
(3 par défaut, possibilité d’en ajouter) - Camera - Tilemaps (décors en tuiles, comme sur les 1ers Zelda) - Sons (musiques / effets sonores) - Etc….
Code Git
TUTORIAL git clone https://github. com/alvinberthelot/phaser-example-arkanoid cd phaser-example-arkanoid npm install gulp
localhost:3000
TUTORIAL git checkout game
Press start
Phaser init var Phaser = require('phaser'); var SCALE = 3;
var game = new Phaser.Game( 120 * SCALE, 60 * SCALE, Phaser.AUTO, 'phaser-example-arkanoid', { preload: _preload, create: _create, update: _update }, false, false );
Loading assets function _preload() { game.load.image('ball', 'game/assets/ball.png'); }
Add sprite function _create() { var ball = game.add.sprite(x, y,
'ball'); }
Change game function _update() { if(ball.x > ...) { ...
} }
UNLOCK LEVEL 1 1. Add background colour to the game
2. Show ball in the game
PASSWORD LEVEL 1 git checkout feat/game-view
Add life to your sprite function _update() { ball.x +=
10; }
Add physics function _create() { ... game.physics.enable(ball, Phaser.Physics.ARCADE); }
Velocity function _create() { ... var angle = 0; ball.body.velocity.setTo(
Math.cos(angle) * ballSpeed, Math.sin(angle) * ballSpeed ); }
Collide function _create() { ... ball.body.collideWorldBounds = true; }
Keep dynamic function _create() { ... ball.body.bounce.set(1); }
UNLOCK LEVEL 2 1. Move the ball in the old
school way 2. With physics the ball can’t exit 3. Use velocity instead of the old school way and add bounce
PASSWORD LEVEL 2 git checkout feat/game-physics
Add controls function _create() { ... cursor = game.input.keyboard.createCursorKeys(); }
function _update() { ... bar.body.velocity.x = 0; if (cursor.left.isDown) { bar.body.velocity.x = - barSpeed * SCALE; } else if (cursor.right.isDown) { bar.body.velocity.x = barSpeed * SCALE; } }
Collide bar / ball function _create() { ... bar.body.immovable =
true; } function _update() { ... game.physics.arcade.collide(bar, ball, null, null, this); }
function _update() { ... game.physics.arcade.collide(bar, ball, null, _reflect, this); }
function _reflect(bar, ball) { ... } Action when collide
function _reflect(bar, ball) { if (ball.y > (bar.y + 5))
{ return true; } else { var rate = (1 - (ball.x + ball.width * 0.5 - bar.x ) / bar.width); if(rate < 0.1) rate = 0.1; if(rate > 0.9) rate = 0.9; var angle = - Math.PI*rate; ball.body.velocity.setTo( Math.cos(angle) * ballSpeed, Math.sin(angle) * ballSpeed ); return false; } } Action when collide
UNLOCK LEVEL 3 1. Add a bar and move it
with the keyboard 2. Add physics between ball and bar 3. Calculate new angle when ball touch bar
PASSWORD LEVEL 3 git checkout feat/game-keyboard
Create a brick function _create() { ... var brick =
game.add.sprite(x, y, 'brick'); brick.scale.set(SCALE); game.physics.enable(brick, Phaser.Physics.ARCADE); brick.body.immovable = true; }
Collide ball / brick function _update() { ... game.physics.arcade.collide(ball, brick,
null, null, this); }
Group of brick function _createBricks() { var bricks = game.add.group();
var widthBrick = game.cache.getImage('brick').width; var heightBrick = game.cache.getImage('brick').height; for (var i = 0; i < 10; i++) { for (var j = 0; j < 6; j++) { var brick = _createOneBrick( widthBrick * SCALE * i, heightBrick * SCALE * j, 'brick'); bricks.add(brick); } } return bricks; }
Kill a brick function _update() { ... game.physics.arcade.collide( ball, bricks,
null, _breakBrick, this); } function _breakBrick(ball, brick) { brick.kill(); return true; }
UNLOCK LEVEL 4 1. Create a brick 2. Create a
group of bricks 3. Kill a brick when the ball touch it
PASSWORD LEVEL 4 git checkout feat/game-bricks
Pause function _create() { ... game.paused = true; spaceKey =
game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(function() { game.paused = !game.paused; }, this); }
UNLOCK LEVEL 5 1. Init bar, ball and bricks with
game dimensions 2. Game paused by default 3. Toggle pause with spacebar
PASSWORD LEVEL 5 git checkout feat/game-paused
Show text var message; var style = { font: '32px
Arial', fill: '#ffffff' }; message = game.add.text( game.width * 0.5, game.height * 0.5, 'Ready ?', style); message.anchor.set(0.5); message.text = 'Bye';
Prepare WebFont // The Google WebFont Loader will look for
this object, so create it before loading the script. WebFontConfig = { active: function() { game.time.events.add( Phaser.Timer.SECOND, _createMessage, this); }, google: { families: ['Pacifico', 'Cookie'] } };
Use WebFont function _preload() { ... // Load the Google
WebFont Loader script game.load.script( 'webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); } var style = { font: '32px Cookie', fill: '#ffffff' };
UNLOCK LEVEL 6 1. Show text when game paused 2.
Load web font 3. Show text when win or lose
PASSWORD LEVEL 6 git checkout feat/game-text
Class Brick var Brick = function(game, x, y, image) {
Phaser.Sprite.call(this, game, x, y, 'brick'); this.scale.set(SCALE); this.game.physics.enable(this, Phaser.Physics.ARCADE); this.body.immovable = true; }; Brick.prototype = Object.create(Phaser.Sprite.prototype); Brick.prototype.constructor = Brick; var brick = new Brick(...);
Handle events Brick.prototype = Object.create(Phaser.Sprite.prototype); Brick.prototype.constructor = Brick; Brick.prototype.destruct =
function() { this.events.onKilled.addOnce(this._onKillHandler, this); this.kill(); }; Brick.prototype._onKillHandler = function() { ... };
Particles Brick.prototype._onKillHandler = function() { var emitter = this.game.add.emitter(0, 0,
100); emitter.makeParticles('brick-dust'); emitter.x = this.x + this.width * 0.5; emitter.y = this.y + this.height * 0.5; emitter.minParticleSpeed.setTo(-50 * SCALE, -50 * SCALE); emitter.maxParticleSpeed.setTo(50 * SCALE, 50 * SCALE); emitter.minParticleScale = 1 * SCALE; emitter.maxParticleScale = 1.5 * SCALE; emitter.start(true, 300, null, 10); this.game.time.events.add(2000,function() { emitter.destroy(); }); };
UNLOCK LEVEL 7 1. Create specific class for brick 2.
Destroy bricks with particles
PASSWORD LEVEL 7 git checkout feat/game-particles
Gamepad function _create() { ... game.input.gamepad.start(); gamepad1 = game.input.gamepad.pad1; }
function _update() { ... var mainAxis = gamepad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X); if (gamepad1.isDown(Phaser.Gamepad.XBOX360_DPAD_LEFT) || mainAxis < -0.1) { bar.body.velocity.x = - barSpeed * SCALE; } ... }
Audio function _preload() { ... // Load sounds game.load.audio('sound', 'game/assets/sounds/sound1.ogg');
} function _create() { ... sound = game.add.audio('sound'); } function _update() { ... sound.play(); }
BONUS LEVEL Your rules Add sounds Try gamepad
Questions
Thank you