How to change a square tile on a tilemap?
by Carlos G. Varela · in iTorque 2D · 06/19/2010 (5:32 am) · 9 replies
Do you remember Mario breaking his platform on top?
How we can do this when dealing with tilemaps? How to change just one square tile of your tilemap?
When you do a tilemap, after that you need to put some boxes with collision, etc. over this tilemap, but the question is:
Do I need to put a this kind of boxes over EACH tile of the tilemap?
Please, answer me Nooooo! : )p
How we can do this when dealing with tilemaps? How to change just one square tile of your tilemap?
When you do a tilemap, after that you need to put some boxes with collision, etc. over this tilemap, but the question is:
Do I need to put a this kind of boxes over EACH tile of the tilemap?
Please, answer me Nooooo! : )p
About the author
10+ years IT Consultant, please see http://carlos.varela.com http://www.idealius.com/blog
Recent Threads
#2
But just one question, please, will I need to do collisions boxes for all the tiles on the tilemap?
06/20/2010 (3:33 pm)
thanks! I will check it!But just one question, please, will I need to do collisions boxes for all the tiles on the tilemap?
#3
They have a bunch functions that read clicks and add/change graphics. There might be an algorithm for collisions for when you are moving pieces. Maybe someone who knows about the tilemap, could answer for sure.
I used the creating tilemap stuff and the clicking parts.
06/20/2010 (5:37 pm)
The link for the tutorial is docs.torquepowered.com/tgb/official/content/documentation/Tutorials/Checkers/1%2...They have a bunch functions that read clicks and add/change graphics. There might be an algorithm for collisions for when you are moving pieces. Maybe someone who knows about the tilemap, could answer for sure.
I used the creating tilemap stuff and the clicking parts.
#4
I use this technique a lot in my game. I use a sprite sheet, made up of image cells. An image for a particulat tile is referenced to a given frame in the sprite sheet. Then, when a brick is hit I change the cell frame number to alter the sprite for that particular brick. You can even have tiles with animated sprites, and change the animation when a tile gets hit. Tile maps are very powerful, and you can a lot of interesting things with them.
Regarding the collisions. You would generate a single collision callback for the whole tilemap layer (which might contain several tiles). The collision callback provides information that can be used to determine which tile was hit. The callback gives you the logical tile position withing the tilemap, which then has to be converted to the actual screen position. If the tilemap is moving, you'll need to store the position of the tilemap, and then use that information to calculate the screen position.
Most of this is covered in the breakout tutorial:
http://www.torquepowered.com/community/forums/viewthread/73649
Hope it helps!
06/20/2010 (5:53 pm)
Another very good tutorial is the breakout tutorial. That one demonstrates how to change tiles. For example, when a brick is hit, it might change color or break apart. In his tutorial he uses KEY frame images, but you can achieve the same effect using CELLs.I use this technique a lot in my game. I use a sprite sheet, made up of image cells. An image for a particulat tile is referenced to a given frame in the sprite sheet. Then, when a brick is hit I change the cell frame number to alter the sprite for that particular brick. You can even have tiles with animated sprites, and change the animation when a tile gets hit. Tile maps are very powerful, and you can a lot of interesting things with them.
Regarding the collisions. You would generate a single collision callback for the whole tilemap layer (which might contain several tiles). The collision callback provides information that can be used to determine which tile was hit. The callback gives you the logical tile position withing the tilemap, which then has to be converted to the actual screen position. If the tilemap is moving, you'll need to store the position of the tilemap, and then use that information to calculate the screen position.
Most of this is covered in the breakout tutorial:
http://www.torquepowered.com/community/forums/viewthread/73649
Hope it helps!
#5
I think this would be work for me, thanks again.
In my case, I do not use physics, I think collisions whait for physics events, in that cases anyone can change it's tile for nothing and then spawn a new scene object, in the same position, in this case with collisions enabled to interact with physics desired, I think, or just put this same object over the tile on the tilemap.
06/21/2010 (1:12 am)
Thanks a lot!I think this would be work for me, thanks again.
In my case, I do not use physics, I think collisions whait for physics events, in that cases anyone can change it's tile for nothing and then spawn a new scene object, in the same position, in this case with collisions enabled to interact with physics desired, I think, or just put this same object over the tile on the tilemap.
#6
It's not completely clear to me what you are asking, but a tilemap basically behaves just like another other scene object regarding physics and collisions. The only difference with tile maps is that the scene object is made up of smaller sub-objects, if you know what I mean. You can then change any tile in whatever way you want, so you have much smaller granularity in terms of what can be changed, which is much more powerful than having to change the whole sprite, for example. For example, you could have an object in your scene that is made up of smaller pieces, like a jigsaw puzzle picture, and you can then break apart that image in any way you want. I've used that for exploding a monster into small pieces, for example. You can do whatever you want, and you can change individual tiles according to whatever event you desire, whether it is a collision event, a timer, or anythings else.
In my case, I've only ever generated one collision event for the whole tilemap, and the collision callback function is then responsible for deciding which tile is the one that was hit.
Not sure if that helps, but I hope so :).
Mark
06/22/2010 (10:13 pm)
Hi Carlos, It's not completely clear to me what you are asking, but a tilemap basically behaves just like another other scene object regarding physics and collisions. The only difference with tile maps is that the scene object is made up of smaller sub-objects, if you know what I mean. You can then change any tile in whatever way you want, so you have much smaller granularity in terms of what can be changed, which is much more powerful than having to change the whole sprite, for example. For example, you could have an object in your scene that is made up of smaller pieces, like a jigsaw puzzle picture, and you can then break apart that image in any way you want. I've used that for exploding a monster into small pieces, for example. You can do whatever you want, and you can change individual tiles according to whatever event you desire, whether it is a collision event, a timer, or anythings else.
In my case, I've only ever generated one collision event for the whole tilemap, and the collision callback function is then responsible for deciding which tile is the one that was hit.
Not sure if that helps, but I hope so :).
Mark
#7
Can you guys send your apps store links in order to buy your games as a thanks to your help, please?
Does your games have support for the iPad? I need to fill my new iPad. ; )p
Acctually, I am studying the code for breakout and checkers samples after continue.
06/23/2010 (1:03 am)
Thanks, Mark and Dean again!Can you guys send your apps store links in order to buy your games as a thanks to your help, please?
Does your games have support for the iPad? I need to fill my new iPad. ; )p
Acctually, I am studying the code for breakout and checkers samples after continue.
#8
http://www.torquepowered.com/community/forums/viewthread/115281
In the meantime, although I don't have a game out, I did post some code that you might find helpful. It's basically a port of the original Breakout Tutorial ported to the iPhone, although it probably will only run on iTGB 1.3.1 as that is the version I used. Anyway, it might be helpful:
http://www.torquepowered.com/community/forums/viewthread/115043
06/24/2010 (12:06 am)
Hey Carlos, no problem, it is good to hear that our comments are helpful. I'm still working on my first game, so I have nothing out yet, but Dean does have a game out. It's definitely worth a d/l, check out his post here:http://www.torquepowered.com/community/forums/viewthread/115281
In the meantime, although I don't have a game out, I did post some code that you might find helpful. It's basically a port of the original Breakout Tutorial ported to the iPhone, although it probably will only run on iTGB 1.3.1 as that is the version I used. Anyway, it might be helpful:
http://www.torquepowered.com/community/forums/viewthread/115043
#9
Congrats!
Dean:
Please, change the explosion, replace for another like shooter.
I am not sure, but when finish a level, I don't see a "continue to next level", the player need to go to the level menu in order to select the next one.
About the new clocks, I really prefer the actuals with color, it's more clear to understand to see the blue color and the yellow to red colors, I think. Maybe you can put too on the new clocks.
Please, make your buttons "homogeneus" , the same design for all your buttons, if you are planning to change the arrows for circles, then put another 2 button with circle too, the pause and the drop water. Maybe the drop water can be in graphic too, with some "splash" graphic, I think.
I am not sure, but when you have damage and go for water on the lake, you do not recover your health, is this correct?
Again, thanks and congrats!
06/24/2010 (1:23 am)
Just to say bought and rated 5 stars!Congrats!
Dean:
Please, change the explosion, replace for another like shooter.
I am not sure, but when finish a level, I don't see a "continue to next level", the player need to go to the level menu in order to select the next one.
About the new clocks, I really prefer the actuals with color, it's more clear to understand to see the blue color and the yellow to red colors, I think. Maybe you can put too on the new clocks.
Please, make your buttons "homogeneus" , the same design for all your buttons, if you are planning to change the arrows for circles, then put another 2 button with circle too, the pause and the drop water. Maybe the drop water can be in graphic too, with some "splash" graphic, I think.
I am not sure, but when you have damage and go for water on the lake, you do not recover your health, is this correct?
Again, thanks and congrats!
Torque 3D Owner Dean Parker
Serendip Games
The checker tutorial for tgb has some code for accessing the tilemap, I have used the syntax for my game in itgb.