Phaser For HTML5
Phaser For HTML5
What is canvas?
A canvas is a rectangle in your HTML page where you can use
JavaScript to draw anything you want.
credit: Nintendo
What is Phaser?
Phaser is an open source JavaScript framework made for HTML5
game developers by HTML5 game developers.
Whats a framework?
Frameworks help to reduce the amount of time
spent reinventing the wheel.
!
Local servers
Local servers allow you to test websites youve programmed
without an internet connection.
!
Find htdocs
Check if it worked!
Go to localhost/mygame
github.com/photonstorm/phaser
Move phaser.min.js
Our game
Collect the pigcats!
Enemies switch between dangerous & safe
If you collect the pigcats, you win!
If your health goes down to 0, you lose!
Polish it with start, win, and lose screens
Variables
Variables are useful for storing data that may change throughout the
course of your app (e.g. your players health)
Variables
Variables let you refer to the same information many times
If you need to change that information, you only have to do it once
!
For example, best friends may change but the label stays the same:
!
Functions
Function: a named section of a program that does a specific task
Wraps up code in an easy-to-reference way
Parameter: additional information you can give the function to
change the output
Function structure
function fetch(dog) {
run to the ball;
pick up the ball;
bring the ball back;
};
Calculations
+ (add)
(subtract)
* (multiply)
/ (divide)
var addition = 13 + 22;
var division = 100/15;
preload() function
create() function
update() function
CREATE
UPDATE
DRAW
X=0
y=0
y=HEIGHT
x=WIDTH
X=0
y=0
x=WIDTH
(3,2)
y=HEIGHT
game.input
game.input.keyboard.createCursorKeys();
+
conditional statements
Conditional statements
if (squirrel){
console.log(squirrel!);
} else {
console.log(bark!);
}
!
Groups
enemies