Search⌘ K

Implement Functions to Create and Update the Game

Explore how to implement core game functions like createGame and updateGame using JavaScript and the Phaser library. Understand setting up game worlds, physics, sprites, animations, and collision detection to build a Frog Jump game. This lesson equips you to manage game state and interactions effectively.

Introduction

In the previous lesson, we initialized all the different game states required for the game. Now, we need to implement the createGame() and updateGame() functions, which are called from the GameState state created earlier.

Implement the function to create the game

Let's start with the implementation of the createGame() function. We'll be implementing the following steps in this function:

  1. Set the game world coordinates using the setBounds() function and specify the (x, y) coordinates we want the game world to start from and the width of the game world. These can be thought of as the dimensions in which our game is going to be rendered.

  2. Start the physics system for our game to apply velocities, gravities, and so on to the game objects.

  3. Generate the jumps array for 29 islands (the 30th30^{th} ...