Phaser: Implementing Multiple Scenes for Better Organization and Flow

Welcome to the next installment of our Phaser series! In this blog post, we will explore how to create and manage multiple scenes in Phaser games. By organizing your game into separate scenes, you can easily switch between different sections or levels while maintaining a clear and organized structure. In previous examples, we learned how to create a single scene by passing an object with function references to the scene property of the Phaser....

Phaser: Keyboard Events

This blog post is part of a series on Phaser. If you haven’t read the first post yet, you can find it here. Unlike mouse events, which are fired on a GameObject, keyboard events are not directly linked to any specific GameObject. Instead, we listen for keyboard events on the this.input.keyboard object. To listen for keyboard events, we can use the following syntax: this.input.keyboard.on(<event>, function() { // event handler code }) The <event> parameter is a string that can be either keydown or keyup, which allows us to intercept all keys being pressed or released....

Phaser: Mouse Input

In this blog post, we will learn how to handle mouse input using Phaser. This is a part of our Phaser series, so if you haven’t already, make sure to check out the first post here. To make any GameObject interactive, all we need to do is call the setInteractive() method on it. For example: text = this.add.text(100, 100, 'test'); text.setInteractive(); Once a GameObject is interactive, we can start listening for events using the on() method....

Phaser: Physics

This post is part of a Phaser series. Click here to see the first post of the series. Phaser offers three different built-in physics engines: Arcade, Matter.js, and Impact (Impact.js compatible). In this post, we will focus on the Arcade physics engine. To enable the Arcade physics engine, add a physics property to the Phaser.Game initialization config object: const config = { //... physics: { default: 'arcade', arcade: { debug: false } } } You can add physics to a single GameObject by using the this....

Phaser: Playing Sounds

Welcome to another post in the Phaser series. In this post, we will learn about playing sounds in Phaser and how to effectively use them in your games. Preloading Audio Files Before we can play an audio file in Phaser, we need to preload it and assign it to a label. To do this, we use the this.load.audio() method. Here’s an example: function preload() { this.load.audio('sound', 'sound.mp3'); } In the above code, we are preloading an audio file named “sound....

Phaser: Scenes

Tags: Phaser, Scenes, Game Development Scenes play a crucial role in defining the structure and behavior of a game in Phaser. By passing them as properties to the scene object, we can configure the game according to our requirements. In Phaser, we can define three main events within a scene: preload: This event is used to load external assets such as images, audio, and other resources required by the game. create: The create event is called when the game is first created....

Phaser: Sprites

Welcome back to the Phaser series! In the previous post, we learned how to add images to our Phaser game. If you missed it, you can check it out here. In this post, we will explore another important GameObject in Phaser - sprites. Sprites are similar to images, but they have one key difference - they can be animated! Let’s start by adding a sprite to our game. First, we need to preload the sprite in the preload function:...

Phaser: The Canvas

Phaser games utilize the HTML <canvas> element for rendering. If you’re unfamiliar with the Canvas API, I discuss it in detail in my Canvas API tutorial. When working with Phaser, we create a canvas with a specific width and height, and then draw on it. While CSS cannot be used to style elements within the canvas, Phaser (along with other canvas-based libraries) abstracts away many of the low-level details, allowing us to focus on the application code....

Phaser: Understanding the Game Loop

This blog post is part of a series on Phaser. Check out the first post here. In Phaser, we have three different scenes: preload(), create(), and update(). While preload() and create() are run only once, update() is constantly called in an never-ending loop until the game ends. In this example, we create a text object that slowly moves towards the bottom right corner of the canvas: let text; function create() { text = this....

Pointers in Go: A Guide to Using Pointers in Go Programming

In Go programming, pointers are an essential concept to understand. They allow you to directly access and manipulate the memory address of a variable. This blog post will guide you through the basics of using pointers in Go. Let’s start with an example. Suppose you have a variable called age with an initial value of 20. To get the pointer to this variable, you can use the ampersand (&) operator:...