![]() Before we worry about the data side of things, let’s just focus on switching. Now that we have multiple scenes each with their own lifecycle events, we probably want to switch between them and even pass data between them. Switching and Passing Data Between Scenes If you run the game, you should see the scene with the image. You can always navigate between them, but it is important to know which one will display first. The order is important because the first scene in the array will be the default scene. Notice that we’ve added both scenes to our scene array. ![]() Within the index.html file, add the following markup: To see what I’m talking about, create a new directory on your computer with an index.html, scene-one.js, and scene-two.js file inside. Rather than dumping everything into an index.html file or similar, we need to have a class for every scene that we plan to use. Creating a New Phaser 3.x Project for Multiple Scenesĭepending on how you’ve been creating Phaser games in the past, designing your game for multiple scenes could look very different in terms of code formatting. Let’s work towards reproducing the above example. Upon some kind of trigger, the scenes are switched, and in this example the first scene with the plane, passes a message to the second scene. We have two scenes in the above example, one with a plane, and one with some game over text. We’re not doing much in the above image, but that doesn’t make it any less important. ![]() To get an idea of what we plan to accomplish, take a look at the following animated image: In this tutorial, we’re going to see how to create multiple scenes, switch between them, and pass data between them, using Phaser 3.x and simple JavaScript. These screens can be thought of as scenes in a game, the same way you can think of scenes in film.Įvery scene that you have in your game represents a clean slate, or a fresh starting point for that particular subsection of content. For example, you might have an initial menu screen, a main gameplay screen, and a game over screen. When you’re building a game, you’re probably going to have more than one screen.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |