Game Development Community

Can Tilemaps Have Components?

by John Kanalakis · in Torque X 2D · 12/21/2006 (2:45 am) · 6 replies

I've been trying to add custom component code to a tilemap layer without much success. After some experimentation, I've discovered a couple things: First, my component works fine with a T2DSprite object. Second, the existing Physics component has no affect upon a tilemap object. So, I've concluded that tilemaps can not support TorqueComponents. Is this true? And if so, is this by design?

About the author

John Kanalakis is the owner of EnvyGames, an independent game development studio in Silicon Valley that produces games and tools for Xbox 360, Windows, and the Web.


#1
12/21/2006 (11:20 am)
You can add components to tile layers, or at least you should be able to. How are you determining that it isn't working? Is _InitComponent not getting called? Is ProcessTick not getting called? Or does the component not even show up in the list of components?
#2
12/21/2006 (11:26 am)
I meant to note a couple things about the tile layers though:

1) They don't currently support rotation, even fixed rotation. This will be fixed for 1.0.

2) They don't currently support changing position (or rotation). Not sure if this will be fixed for 1.0. I'd hope it would be, though.

3) Add physics and collision to them at the same time at your own risk. Of course, this won't work till 1 & 2 are resolved anyway, but the problem is more intrinsic than just 1 & 2 being broken. The thing is that for the tile layer to move and collide, it will essentially have to collide against everything in the world. This can present some performance issues. Worse yet, in TGB and TX you don't do collision when rotating (collision due to rotation is resolved as overlap). If you want to move/rotate the tiles, your best off turning off collisions on the tile map. You can still have other things in the world collide with the tile map when they move (so tile map moves, no collisions; object moves, collisions).
#3
12/21/2006 (11:43 am)
Thanks Clark, that's great info. Here's some more details... the component does appear within the TGBX list and can be assigned to the TileMap with no problems. It even makes it into the .txscene file just fine. But the _InitComponent() and ProcessTick() methods are never called. The component is very simple at the moment and only initializes some internal data when _InitComponent() is called - ultimately, the component will move the TileMap around horizontally & vertically (no rotation and no collision checks).
#4
12/21/2006 (12:13 pm)
I just tested a tile layer here and it definitely calls _InitComponent (collisions depend on this happening). You sure your component is in the component list? Check the component property on the tile layer and see that your in the list. Also need to be in the list before you are added to the scene since components cannot be added on the fly (this is documented but we should probably have some asserts and exceptions for that).
#5
12/21/2006 (2:48 pm)
Okay, here's what I've discovered. Everything seems to work fine when the tilemap is NOT a template. When the tilemap IS a template, the _InitComponent() is not called (maybe this is by design).

In my particular case, I have 4 or 5 tilemaps that are spawned at different intervals and positioned by the player, like building blocks. So, I thought it would make sense to create the 4 or 5 tilemaps off-screen and specify them as templates. Then, when the time is right, I can spawn them and place them in the game.

If a template is not the right approach, I can try creating a new tilemap on the fly and copying the reference tilemap data into the new object. Anyway, thank you very much for your help.
#6
12/21/2006 (4:54 pm)
Sounds like tile maps aren't properly cloning then. They should by design, but looking at them it doesn't look like anyone every implemented the copy to method. You probably would get an assert in the debug build since it verifies that all the fields are copied correctly. (If you aren't cloning the template object before registering it, then it won't properly add and that would also explain why you wouldn't get an init component callback...but that would also cause an assert).