Room System

how can i make a room system to load / unload objects, switch between rooms and draw sprites?

I would think this is really just an issue of organizing your entities/actors/characters into folders/scenes/rooms (whatever you wanna call them).

I’m assuming we’re starting off with one big list of entities that you iterate over in your Draw and Update calls in your Game class or something.

So if you want to seperate your entities into rooms your Game class could instead have a list of rooms that each have their own list of entities and you would instead iterate over your rooms in the Game class.

This is the basic idea though, I think it’s difficult to give a solid answer to this question without knowing where you’re at.

when I was figuring out how to structure my project I took a lot of inspiration from other game engines (Unity/ Godot/ GameMaker). it was pretty useful just seeing in the files what actually was changing when I would make changes to a scene in Unity.

I’m just kinda learning as I go, but this is what I have so far.

Game => Locale (Scene Group) => Scenes (Entity Group) => Entities => Components

A scene loads stuff from it’s JSON file and keeps the entities generated in it’s own list so we can get rid of it when we’re done with that scene. I also have a “keep on load” scene (just like in Unity) for stuff that should persist between scenes/ rooms

Not sure this is the most efficient way to do it, but the way I do it is that each room/scene is a DrawableGameComponent; when I need to change the scene/room, I call a function which just disables the current one and toggles its visibility. And in turn, it enables the next room and makes it visible.

There are TONS of wikis of how to generate rooms/dungeons that even show the code in C# OR show the steps to generate those dungeons/rooms. Its good learning experience :].

I think you need to create abstract class Room with fields like - background (Texture2D), music at start (or any other name idk); and virtual methods that could play music (virtual methods is methods that you can override in derived class). Then you need to create classes as many as you have rooms and just derive these classes from abstract class Room. Initialize fields that we assigned on the Room class and override methods that you created. You can change between rooms in Game classes or make somthing like room order (last thing is not good lmao). I’m 15 and if I said something wrong pls dont throw tomatoes at me :smiley: anyway, that’s my answer and advice!

Firstly, stuffing rooms with backgrounds and music is a pretty bad design. This should be handled by different systems. Secondly, it’s been two years, I don’t think the guy needs help with this anymore. Don’t necropost.

Why it is a pretty bad design? What this problem solve you can suggest?

Because this is hard to extend, bloated and not very useful at all. A room is a container for entities, that’s it. That’s all it should do, and all the features of the room should be focused on that. Backgrounds and music are completely unrelated to it and can easily be covered by your entity system.

1 Like

Ok thanks!