So I’ve been trying out this new system where you create a tile once and make it static, and then I set the tiles in an array to that static tile, so its the same instance of the tile. Then, I tried to do lighting, and it didn’t work, because since its all the same tile, all the tiles have the same data, I can’t modify individual tiles. I was wondering if there was a way to get around this? Or do I just have to suck it up and create a new tile instance for every position in the array?
Don’t worry about the instance count of your Tile objects, as long as they don’t carry around a lot of exclusive data with them. Just make sure they (the instantiated tiles) share references for their members wherever possible.
For example, if you have two grass tiles, they should both reference the same spritesheet from which they gather their tile graphic.
Yeah, I wouldn’t make them all the same instance. I would add in ‘lighting tiles,’ that is just a black tile with an alpha scale. Like if it is really dark, alpha of .9, if it is really bright, alpha of 0. Simple! However, this would require non-static lighting tiles. I think that it’s not worth the trouble of making them static though. I would just make them seperate instances. I think that the resources spent wouldn’t be too high. Like said before, just make sure you aren’t loading the same resources more than once.
Yeah, I just realized how much of an idiot I was for making my tiles static. It’s a cool idea for terrain that doesn’t need to be customized too much, but that’s about it. I don’t want to overlay light tiles either, I’d rather just create new instances and sort my tile creation calls so I only have a specific texture binded once. Thanks guys!
Store it in a 2 axis matrix such as matrix[width][height] define your static object to each position and have your lighting either render the pixel or not render the pixel based on the system you are using.
What you’re using is an array, not a matrix, and that wouldn’t work either because every tile has the same instance of the same sprite, which holds the rgb values for the texture. So every time I modify the sprite, it modifies all the the tiles.
2D arrays are often thought of as matrices, because they represent the same concept of a column-and-rows modeling of data. Speaking in abstract terms like lcass was doing, the argument is merely one of semantics.
Ok, I’ve never thought of them like that, sorry Icass! I just dont like the term matrices for storing data because really arrays(at least in the case of my tile game) store instance of something, not numbers, so it really doesn’t fit. If I was just storing numbers in the array, it would be different.
Still, there’s no point in debating over this, so thank you all!
Wait you are actually modifying the graphics of each tile? if you are doing that have the object that holds the commands but overlay the graphics. Then you can modify different sections at a time without screwing with your objects.
No, I don’t want to use overlays because its easier to just create a new instance if my tile. With an overlay I’d need to render my tiles and the overlay, which would be modified at every tile, so I’d essentially be drawing twice the amount of vertices, and that’s just wasteful. The static tile system is nice to use, but it’s only good for tiles that are going to be exactly the same. I already moved my tile system over to just creating new tiles.
make separate instances of your tile, holding the x and y coords, as well as light level as instance variables, and all other data, like textures and reacting to the player, static.
You will have to draw each instance each turn, but you can save on lighting updates by having them update only when changed or surroundings changed by the environment or player.
I know, thats how I had it originally, I just didn’t think before I implemented the static tile system.
Ahh thats not what i meant, I meant dont draw the tile but rather have the tile graphics in the overlay then edit it in the overlay image.