Making a first-person point-and-click adventure game, and need some guidance on coding structure/practices

Hello. I’m new to Phaser and game dev, though I do have a fair bit of coding experience outside of games. I’m currently working on my first Phaser project, which is a first-person point-and-click adventure game in the style of Myst. I’ve built a functional prototype in which I can click between a few screens, and I could probably continue this way. However, I’m not confident in the structure of the code. If I’m doing something wrong, I want to fix it early so it doesn’t come back to bite me later in development.

My main concern right now is that the game currently only consists of a single Scene object, and I’m wondering if keeping it this way (or even using a small number of scenes) could be a major problem as the game grows larger. Let me explain:

This game mainly consists of navigating the game “world” by clicking between pre-rendered still screens. Each screen consists of an image and multiple clickable zones (with additional multimedia elements likely being added further down the road). Clicking on a zone will either move the player to a different screen, call a function that otherwise alters the game state, or both.

When changing screens, the image for the current screen is made invisible, and all associated zones are rendered non-interactive, after which the next screen’s image is made visible and the associated zones are made interactive. I keep track of all of this with custom classes. Each screen is represented by a View object, which contains an image as well as an array of ClickZone objects.

I’ve been thinking of instead having every screen be its own scene, but I’m not sure if it would do more harm than good (I’m not terribly familiar yet with how scenes work, so forgive me if any assumptions are way off.). On one hand, It feels like having all these loosely-associated views and zones may be asking for trouble, and a scene would more neatly tie all aspects of a screen together. On the other hand, I’m worried that scenes might not be lightweight enough, and that a scene may be way too bulky a data structure to have a separate one for EVERY screen, since there will be a LOT of different screens in this game (usually one for each cardinal direction for every node on the map). What’s your advice here?

Additionally, is there any other aspect of the design that raises any red flags? Here’s a diagram to better illustrate the structure of the program:

Views and zones are populated from a json data file. cursorPath specifies the custom mouse cursor associated with a particular zone.

Any guidance would be greatly appreciated.

2 Likes

Hi,
I think you made it right.
Here’s how i use scenes in my game, it’s a metroidvania platformer, so lot of different rooms connected with doors.

  • one scene with just a logo, this scene preload the necessary assets for the next scene(background and loading bar)
  • a loading scene, here i preload all the assets needed in the game, with a loading bar showing progress
  • a menu scene
  • a option scene
  • the main game scene
  • the hud scene
  • gameover scene
  • end scene

So each scene has a definite and unique role.
The main game scene has methods to change rooms when player pass a door, i have more than 100 rooms…making 100 scenes isn’t the way to do imo.
The hud scene and game scene are loaded together, and i pass data from the game scene to hud by emitting events.

Hope this helps

2 Likes

If you use one scene per screen then all of this will be done for you.

You can stop a scene to clear its objects, then restart later if needed; or you can remove (destroy) a scene that is no longer needed.

You can also restrict the plugins running in a scene, that can slim it down a little bit.

1 Like

Thanks! It’s good to know that scenes are workable for this.

I have a couple questions though. In all the examples I’ve seen, scenes are created from classes, and not any individual instances of a class. Is it possible to create a scene from a class instance rather than the class itself? I plan to populate different game screens via data files, and this will not work if I have to write a new class definition in code for every single screen.

Also, can you preload assets of a scene before you even start a scene? I see that each scene has its own preload function. I want to be able to preload, at the very least, a significant portion of the game screens, before starting up, which means I can’t wait until a scene is called to preload its assets. I want to preload many scene’s assets before any are started.

Anywhere you add a scene you can pass either a class or a class instance. If you pass a class, you can usually configure the scene by passing a data argument, which the scene receives in its init() method.

The asset cache is global and you can load assets in any scene.

1 Like

Ah, that’s great to hear. This is everything I need, then. Thanks again!

I’m still not entirely sure what’s best, though. As @BlunT76 noted scenes are still larger and more complex than what you’re using now.

1 Like

Yeah. I should also thank @BlunT76 for letting me know that my current implementation is still a valid one.

Updated to change solution to @BlunT76 because I ended up using a single scene for the main game.

Does this mean you’re rendering both scenes simultaneously?

Yes, the hud scene is only 20px height and is on top of the game scene

1 Like