Public Group

# A few questions regarding "scene creation" (old zelda style)

This topic is 2592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone.

I'm currently working on a small game with a scene system like the old zeldas. I don't know exactly how this is called, but the way it works is your character moves through many scenes with a fixed camera. All scenes have the same size and they work like a "grid" of tiles. When you run out of bounds on a scene, you move to the connecting one.

Each scene can have things like monsters, portals which lead to different scenes and buttons to trigger events. At first I was going to implement the scenes using a .txt file where a scene would have an ID, the IDs of the surrounding scenes and a matrix of numbers (each number would be a tile). If the scenes only had walls and monsters this would do fine, but since there are other elements it would probably become very confusing (portals for example would lead to different scenes so would have to be different, or have additional info). Besides this, if I wanted a monster to spawn somewhere on the map, that position on the matrix would be the monster ID, but I still want to be able to define the tiles on the floor below the monsters and such (could still do it this way but would have to make different values for the same monster on different tiles or a "background" system).

Instead of using this I guess I could use different matrices for the same scene (one for the tiles only, one for solid/water/etc) and something else for the rest, but this still seems very confusing for portals, buttons and so on. Then I thought about just using XML since I could just define as many objects with as many properties as I wanted to in a scene, but before I start doing anything and risk redoing everything later, I thought I'd ask here for help. If anyone implemented something like this (or has a suggestion on how to), I'd gladly appreciate it. Sorry if this is too confusing (and let me know if you need clarification on something).

##### Share on other sites
I bet they did it this way, and I would suggest doing it like this too. Build your world just like any other 2D grid based map, but keep your camera fixed to specific intervals. So when the player leave the boundaries of the camera, it shifts to the next position.

so say your camera always sees, a 15x15 grid of tiles, it should jump ~7 tiles every time the player reaches the edge. Then you just have to figure out how to force the player to move a full tile every time they reach the edge. It'll probably be a hell-of-alot easier to design an editor for and use aswell.

##### Share on other sites
I used a different approach for my 2d engine. Its not exactly like the zelda style, but it works.
First, create a 2d map as an two dimensional array, where every array X/Y stands for one grid position. In this array, you can load all objects you like, not just background/foreground/mob objects. Once the map loads, it should check if the map size is bigger than your current viewport (your screen). If thats not the case, render the whole map. This is useful for small caves and houses. If the map is bigger than your viewport, you gotta check where the player is located on the grid. Basically, if the player is on the outer ring (which is a half viewport size wide), the map stands still when the player moves.
If the player is in the center, you draw the player in the same spot, the center of your viewport, and move the background in the opposite direction.
I hope I explained the movement and the map creation exactly and it helps you at least a bit ;)

##### Share on other sites
I failed to explain my problem.. I know I can use just one map for all the scenes and just use a stationary camera (I was actually planning on doing this at first but then decided on having multiple scenes instead of just one map and load the adjacent ones when the player is on one scene. In this case you would just change to the appropriate scene when the player went out of bounds). My problem is figuring out a good generic way to load the scenes (or the whole map if I just use a stationary camera) from a file without having a huge amount of IDs for the objects/tiles.

I'll provide an example:

Imagine a 3x3 map/scene where 0 represents some grass tile and 1 some random wall:

1 1 1
1 0 1
1 1 1

Now say I want to add a portal in the middle that sends me to some other scene (or some x,y if it's a map). To represent a portal I could use a number (2 for example) but that wouldn't say anything about the floor below it or where the portal sends to. If there were just 2 different floor tiles, I could just use 2 for portal on top of floor1 and 3 for portal on top of floor2, but this is pretty stupid and still wouldn't tell me the teleport info. I could always work out some format for the number like ttffdddd (t = type, f = floor on bottom, d = data - which could be xxyy in case of a portal or something like that) but this would probably make map creation less intuitive than hard coding it (which is what I want to avoid).

##### Share on other sites
Well since yu want extra info per tile maybe a simple text file with a matrix is not enough. another method would be using several files permap. A tile map and a entity map and a third file which describes the entities. but this all could be solved in one single file using xml.

<map width="2" height="2"> <tile> <!-- Pos: 0,0 --> <graphic value=""/> <entities> <entity type="portal"> <target value=""/> </entity> </entities> </tile> <tile> <!-- Pos: 1,0 --> <graphic value=""/> <entities> </entities> </tile> <tile> <!-- Pos: 0,1 --> <graphic value=""/> <entities> <entity type="monster"> </entity> </entities> </tile> <tile> <!-- Pos: 1,1 --> <graphic value=""/> <entities> <entity type="playerstart"/> </entities> </tile> </map>

##### Share on other sites
do your portals have to be tied to the map? Sounds like your portals are just triggers that set off an event. So why not just store all your triggers in a separate vector from the map, then iterate through them to check if the player has activated it.

With your current idea, what happens if you want your portal to be anywhere on the edge of your scene... do you just copy paste a bunch of the same portal?

##### Share on other sites

Well since yu want extra info per tile maybe a simple text file with a matrix is not enough. another method would be using several files permap. A tile map and a entity map and a third file which describes the entities. but this all could be solved in one single file using xml.

That's what I wanted to know, thanks. I just implemented the scene creation with xml (simillar to what you suggested) and it works great.

Thanks everyone for the help.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
12

• 14
• 22
• 9
• 31
• 18
• ### Forum Statistics

• Total Topics
632617
• Total Posts
3007475
• ### Who's Online (See full list)

There are no registered users currently online

×