Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tile structures

Started by Zephyrox Oct 11, 2001 at 1:24 AM 5 replies 350+ views
Original Post
Zephyrox
Zephyrox
Okay i´m trying to make a simple tile game. Should i have a struct that holds the position of the tile och width and walkability and things like that, the struct also points to a surface witch holds the image of the tile (only that tiles image and nothing else)??? Then i create about 400 of these objects to fill the screen... sounds like a memory waste!! But if i only have mabye 3-4 of these structures and use them many times when i fill the screen, the walkable int can´t be used. Help me, how should i design the code?
GoofProg
GoofProg
Well it''s a game so it is going to take up resources. I would safely say that target for making a game that can run on a 16MB machine.. if you are really into optimizing you could use a structure that uses bits are set.. let''s say..

bit 7 is for a walkover flag
bit 6 is for pick up item flag
bit 5 is for an event flag
bits 0-4 hold an index value for the tiles
0-31 are the for the tile index.. it''s limited to a total of 32 different tiles, but it works.

or use a byte for the tile index and another one for the attributes. Experiment and have fun =)






The nightmare travels across the cosmos with his burning mane.  The trail of ash that is produced. ?Have a nice day!?
Zephyrox
Zephyrox
Okay thanx but the question i really wanted to ask was:
Should i make about 300-400 tile objects to fill the screen width or only one for each type of graphic?
Pyabo
Pyabo
Create enough tile objects to fill the screen... each tile can have unique properties, thus you need one object instantiated for each tile. Do not store the image in the tile object, only an index of what image should be used -- I think you understand this.

If you are really concerned about memory usage, do not use a tile object at all... find another way to do it. Use one 2D array of ints for the image index, and another 2D array of ints for tile properties. This won''t necessarily save you any space though...
shalom
shalom
quote:
Original post by KalvinB

Otherwise you have a large amount of redundant information.




That''s not necessarily true - it really depends on the game. If you''re going to have a simple game where tiles that look the same will ALWAYS react the same, the just making some tiles and have a link to each kind. But if you''re going to have a game where each tile reacts slightly differently, then by all means give each tile its own reaction information.
In my thunking device, what happens to the inherited pointer to the original base class when I override the function & how do I access it in my inline assembly code, assuming that we are referencing the higher byte of the 16-bit variable?
Paradigm Shift 2000
Paradigm Shift 2000
Yeah, but don''t copy the image information of each tile. If you only have say, 256 different tiles, use a byte in the tile structure to store the tile index and store the tile images in an array of 256 surfaces. A wise move would also be to make a reference count on each surface so that the surface doesn''t get deallocated while a tile of that type is still on the screen.

Paradigm Shift 2000
"I am Locutus of Borg. Resistance is Futile." -- Locutus of Borg

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.