(click anywhere to close)
OPEN MENU

[Phaser] An advanced guide

category: Games | course: Phaser | difficulty:

Assuming you've read the beginners tutorial and want to know more...you've come to the right place! In this post I'll cover the more advanced possibilities of Phaser (which are still pretty basic and fundamental really). Nevertheless, if you want to create a nice game, you better know these things.

Grouping

Phaser has created lots of support for grouping of objects, and for a good reason. Grouping objects (for example all the coins, platforms or enemies  in a level) makes it easy for you to go through all the objects of a group and check for something. It also makes it possible to move, rotate, scale, destroy, etc. the complete group all at once. And next to that, it makes your code simpler and easier to read for yourself!

//First define it
var platforms = null;

//Add this in the create function
platforms = game.add.group();

//Enable physics bodies for all members (current and to be added in the future)
platforms.enableBody = true;

//Create a sprite in it (or remove it);
platforms.create(xPos,yPos, someThing);
platforms.remove(someThing);

Groups don't have a physics body themselves. They're just an 'empty' container object, containing all it's children's bodies.

Game vs World

In Phaser, a distinction is made between game and world. Game is the size of the canvas, the size of that rectangle  you are viewing throughout the game. World is the size of the game world. This can be as big as you want, but you can give it a size with the width/height properties, and optionally boundaries by setting the bounds property (nothing can go beyond these boundaries). By default its starting point is at (0,0) and it's as wide as the game is. But, if you for example made a sidescroller game, you would make the world a lot wider than the game.

Tips & Tricks

For Phaser-specific tips & tricks to improve your workflow and make things just a bit easier go to this tutorial: Phaser Tips & Tricks

Physics all the way!

For an explanation of all physics systems in Phaser and how they work, see this overview: Phaser Physics Systems

Nice Preloader

Another useful thing to know when your game grows bigger, is how to add a nice preloader: Phaser Preloaders

Different (Graphical) Possibilities

Whether you just want to test if something works, or you really want the fastest way to the best possible graphics: Phaser Graphics  

CONTINUE WITH THIS COURSE
Do you like my tutorials?
To keep this site running, donate some motivational food!
Crisps
(€2.00)
Chocolate Milk
(€3.50)
Pizza
(€5.00)