2D array to draw a map?
raze_struck
Member, PRO Posts: 141
Does anyone know how to create a 2 dimensional array in Gamesalad. I want to create a metroidvania style map, and have the array draw out the map as you walk through the "castle" on a different scene (map scene)
Comments
Sounds like tables to me ! I'll let one of the resident table experts chime in . . .
Basically replicating this more or less, to draw out the map in different colors. Maybe a loop through the array, to check the position of the player or something.
http://www.processing.org/tutorials/2darray/
2D arrays are possible using tables, but drawing is a problem. There is no for loop and you can't draw images without spawning an actor for each.
However, you could pre-place actors (you only need to fill the camera view) on the scene and load their images from the table (2D array).
@JGary321 explains the method here: http://forums.gamesalad.com/discussion/54918/terraria-styled-game
Here's an example of a game using the method above.
I believe you're referring to this, but I'm still kind of confused as to how I would go about doing this. I'n my case I would have a premade map on the screen with separate image files for the boxes or points, that would change color/ or visibility depending on whether the player overlaps that certain area in the game. To have like 500 boolean's would be insane though. So I'm trying to wrap my head around the method below.
Yes it's possible. I actually was working on a tile based RPG-game and came up with a working version for something like this. Since, the concept is the same it would work for a Terraria style game. Here is the basics.
You do not spawn any tiles whatsoever. You pre-place all the tiles on the screen. For me I did 32x32 tiles. You need at least 2 tiles of overlap on the side and 2 on the top.
Then as you move your character the tiles move also. The tiles change to a different image based on their X/Y in the table grid. Since a table can have 1000 rows and 1000 columns, that would be the number of blocks you can have on one table. Anything more would require additional tables.
Believe it or not the code side was VERY light. It did not take very many rules at all to make this work.
This is the basics for the "blocks". I had a generator to create trees/rocks also. All the generator does is change the tablecellvalue that corresponds to an image. It was a lot of work, but yes it can definitely be done.
If I had a real graphic artist I would be inspired to make something like this... & actually complete it, haha.hint hint
@raze_struck have you used tables before? If not, you might want to take a look at this video by GSHelper:
Basically instead of having 500 boolean game attributes, you would have a table that has 500 cells. You can make it 1D or 2D. I recommend 2D as you're using it for a 2D map.
And for the block actors, you would have a table x and y coordinate (or row and column) attributes that would be used to load the correct values from the table.
Here's a simple project file with 2x2 table and 4 actors changing colors based on the boolean values of the table:
https://www.dropbox.com/s/ox7x91s9tq4gz5o/2DMap.zip
You can see how the map changes when you change the table values.