Game Development Community

Tile Based Game

by Dylan Taft · in Torque 2D Beginner · 04/14/2013 (8:21 pm) · 4 replies

I'm working on porting one of my projects to MIT Torque2D.
I noticed there's no longer classes for tile layers.
Would the new way to do it be to build a TAML file with a bunch of sprites in it and position each accordingly?
My maps could be sized up to like 2000x2000 tiles.
It seems like sprite is a pretty heavy weight object - it's got a lot of properties. Memory wise is this going to be OK?

Or, is there a different object I should use, or am I thinking about this the wrong way?
Should I use SceneObject for static tiles, and Sprite for animated?

I'm working on a module to convert Tiled TMX files files to TAML which can be loaded into a Scene. Almost done, but just kinda wondering what the best way to do static tiles is.

Thanks!

#1
04/14/2013 (8:38 pm)
You will want to use CompositeSprite for this.

The composite sprite will contain sprites and place them based on logical positions. (0,0 1,1 2,1, etc.).

One tricky part to understand when you are used to TileMaps and TileLayers is that a compositeSprite object's center is at "0 0", instead of the expected upper-left corner.

Check out the Sandbox's CompositeSpriteToy for an example.

Also be aware that William Hilke has been working on a TMX to T2D importer : www.garagegames.com/community/blogs/view/22199
#2
04/14/2013 (9:38 pm)
Thanks! Thats what I need. It sounds similar to the old torque.
I was just kinda looking at his work, it seems pretty good.
His implementation is in C++ though, which for me is a bit overwhelming if I need to understand it to modify it. I'd have to learn to build the engine and such and how C++ code is exposed to TorqueScript.

What I'm doing is straight up TorqueScript, and there's some limitations as a result. TorqueScript has an XML parser, so it'd probably be limited to XML CSV based only, instead of Base64 or zlib maps.

Like, I need to do some specific things, like I want to place objects, NPCs, on the map that reference TAML files, and I probably need their properties to create dynamic properties on the underling SceneObject like in the old Torque editor.


http://www.youtube.com/watch?v=yT5_qn0PUGc
http://www.youtube.com/watch?v=e1n2iCDN0wM
Some olderish videos of what I was working on in the old Torque.


I guess I can ask if he can implement that, for him it would probably be just a few lines of code. For me the learning curve is too steep right now to do in C++.
#3
04/15/2013 (9:19 pm)
i50.tinypic.com/23its1i.png
Hmm, I'm nearing completion of my own Tiled TMX loader in TorqueScript, but my darn maps are loading upside-down, haha.

0,0 is still the upper left, in terms of sprite location, right? When you say 0,0, that means, if I set the position of the entire CompositeSprite in the scene to 0,0, 0,0 in the map would be globally some negative position, right?

Trying to figure out why my maps are loading upside-down, I know I'm reading the tiles into the array the correct order.

If nothing else I'm doing this to get a handle on how CompositeSprite works.

Edit: Oh, Torque uses a Cartesian coordinate system, Tiled uses a system where incrementing y values is down. I never had to worry about it before at this level so I never thought about it. Easy enough fix...
#4
04/15/2013 (10:51 pm)
@Dylan : Based on your edit, I figure that you've already figured it out but I will post this just in case others might need clarification on the coordinate system used in the CompositeSprite.

0,0 is in the center of the tilemap, your CompositeSprite's logical space would thus stretch from -tilemapwidth (in tiles) to +tilemapwidth in both X and Y directions.

The weird thing here though is that the logical space of the CompositeSprite is exactly like Box2D and Torque2d.

To give you a clearer idea, (-X,Y) is the upper-left corner, (X, -Y) is the upper-right corner, (-X,-Y) is the lower-left corner and (X, -Y) is the lower-right corner.

Tiled works the other way around, where +Y is down, -Y is up.