5 Time Saving Phaser Classes

Deja Vu All Over Again!

If you ever get a Deja Vu feeling when you are coding, it is probably time to put that code in some form of reusability! I found myself writing a lot of the same things over and over, so I built these classes for my personal library. Here are a few of my most used classes in Phaser.

The Background

What it is: This class takes an image key and creates an image that fills the screen. It does not maintain proportions, so it may not work well with every image

How To Use

The Code

The Logo

What it is: The logo component loads an image and gives it a center anchor and scales it proportionality to a percentage of the screen’s width.

I use this a lot when building title screens

How To Use

The Code

The Thumb

What it is: A Thumb component that loads a sprite and center anchor it. I use it a bit with the grid component below.

How To Use

If you need to add a listener you can access the icon inside the thumb with

 

The Code

The Item Line

What it is: The item line allows you to create a horizontal or vertical line of sprites

How To Use

Then line it up vertically

or horizontally

The Code

The Grid

What it is: The grid component allows you to quickly create a grid of items

How To Use

The Code

I hope you find these as helpful as I have

You can download all of these as part of the Ultimate Game Parts Template

Leave a Reply

Your email address will not be published. Required fields are marked *