Tile Engine in C# and XNA

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
epicasian
Chaos Rift Junior
Chaos Rift Junior
Posts: 232
Joined: Mon Feb 22, 2010 10:32 pm
Current Project: Gigazilla Engine
Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
Programming Language of Choice: C/++
Location: WoFo, KY

Tile Engine in C# and XNA

Post by epicasian »

How would you attempt this?

I am thinking of doing it like this:
Load Map.txt file into an integer array, (Make each layer a different array)
Load TileStrip.png into a Texture2D,
Split each 32x32 tile, and store all the tiles into a Texture2D Tile array,
Create a dictionary that maps the integer array values to Tile array values.

Any other suggestions?

Thanks,
EpicAsian
Last edited by epicasian on Tue May 25, 2010 3:41 pm, edited 2 times in total.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Tile Engine in C# and XNA

Post by Falco Girgis »

Everything sounds great except for the last part:
epicasian wrote:Create a dictionary that maps the integer array values to Tile array values.
A dictionary? Why? The integer array values should directly correspond to your tile values. Otherwise you are going to suffer a SERIOUS, unnecessary performance hit. You should be able to access a tile or object at a current level location by doing something like:

level.tileset[level.map[y][x]].solid

That should demonstrate the relationship between the map and the tile/objectsets.
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Tile Engine in C# and XNA

Post by MrDeathNote »

I wouldn't divide the tilesheet into an array of Texture2D's. That's really memory intesive. What you should really be doing is storing the bounding rectangle of each tile, so you have an array of rectangles that contain the positions of the tiles in the original texture. I'm going to be making a tutorial very soon about creating a very simple map editor and basic tile engine in XNA because i've had quite a few messages about it. They should be on youtube within 4 to 6 weeks (hopefully), i think they could help you alot.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
epicasian
Chaos Rift Junior
Chaos Rift Junior
Posts: 232
Joined: Mon Feb 22, 2010 10:32 pm
Current Project: Gigazilla Engine
Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
Programming Language of Choice: C/++
Location: WoFo, KY

Re: Tile Engine in C# and XNA

Post by epicasian »

Thanks for the replies.

MrDeathNote: I think I'm going to try it on my own, but if I can't figure it out, I will most definitely check out your tutorial.:D

Thanks again,
EpicAsian
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Tile Engine in C# and XNA

Post by MrDeathNote »

epicasian wrote:Thanks for the replies.

MrDeathNote: I think I'm going to try it on my own, but if I can't figure it out, I will most definitely check out your tutorial.:D

Thanks again,
EpicAsian
No problem, i think thats great if you can do it by yourself. It makes it a much better learning experience. I made my first tile engine from scratch by myself and it helped me learn a lot. Good luck with it :)
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Post Reply