Help with Tilemaps
by Danny Mejia · in Torque X 2D · 10/20/2007 (9:31 am) · 17 replies
I have a Tilemap set 8x8.
How would I going about loading images into the Tilemap cel and col are run time.
How would I going about loading images into the Tilemap cel and col are run time.
About the author
#2
10/20/2007 (12:04 pm)
Thats works....but I'm try to place images inside the col and cel not painting. I have a out line around the tilemap so I need to place image in the middle of the cel and col.
#3
John K.
10/20/2007 (1:34 pm)
Sorry, I'm not following. By 'cel' and 'col', are you referring to a Grid Position defined by Row and Column? I can't find cel and col properties attached to the T2DTileLayer, T2DTileObject, or T2DTileType. Maybe posting some code or a screen capture can help.John K.
#4
So I'm trying to port it over the TX.
So right I'm get trying to put my game pice inside each row and column in of the tile map.
10/20/2007 (1:50 pm)
Yes...I'm referring to the grid Position...I'm working on a match 3 game...I have a demo made in flash.So I'm trying to port it over the TX.
So right I'm get trying to put my game pice inside each row and column in of the tile map.
#5
This will fill in every grid position within the tilemap.
John K.
10/20/2007 (2:14 pm)
The code I posted should still work. If you want to fill the entire tilemap, you could create a couple nested loops. Replace the last 4 lines with this...int maxrow = 8;
int maxcolumn = 8;
for (int row = 0; row < maxrow; row++)
{
for (int column = 0; column < maxcolumn; column++)
{
tilemap.SetTileByGridCoords(row, column, tile);
}
}This will fill in every grid position within the tilemap.
John K.
#6
I have my tile maps set up like the Futuristic Strategy Master tutorial. So the tile map is a board. And the game images are pices
10/20/2007 (2:24 pm)
I don't want to paint the tiles...I have the rows and columns outline with a green border...if I call the SetTileByGridCoords is replaces the the border that I have...so I just need to place the object or game images image in side the columns not paint with it.I have my tile maps set up like the Futuristic Strategy Master tutorial. So the tile map is a board. And the game images are pices
#7
This is get a outline and not code.
Like this I have 6 game pices gamepice0-gamepice6.
getGame()
{
int i = rand(0,6);
switch
case 0:
gamepice0;
and so on
than I and take the gamepice in set it POS to a row and column
10/20/2007 (2:45 pm)
Thanks your code works as far as fill the tilmap.....but it deletes the green border...I'm tring to place object inside the row and columns with games pices that can be moved..This is get a outline and not code.
Like this I have 6 game pices gamepice0-gamepice6.
getGame()
{
int i = rand(0,6);
switch
case 0:
gamepice0;
and so on
than I and take the gamepice in set it POS to a row and column
#8
10/20/2007 (2:51 pm)
Thanks for your help...I have to someone to help me with what I'm doing
#9
10/20/2007 (2:56 pm)
Danny, I'm not sure I'm following you. Are you trying to create a bunch of new sprites in code and place them centered on the various tiles of your tilemap?
#10
10/20/2007 (3:03 pm)
Thanks for your help...I have to someone to help me with what I'm doing
#11
-----
| |
| * |
------
The * is a game I want to add the box is the tile map
10/20/2007 (3:06 pm)
Dan I'm make a match 3 game...-----
| |
| * |
------
The * is a game I want to add the box is the tile map
#12
Another way to do it would be to create a second tilemap to just hold your pieces that you could put over top of your background tilemap.
A third approach would be to create your game pieces as independent sprite templates, and then you could create clones of them at the X,Y coordinates of the center of each tile.
Do any of those sound like they would help? I can go into more depth if any of those sound like something you want to do.
10/20/2007 (3:41 pm)
If I understand your problem right, there are a few things you could do. You could modify your art so the pieces also have the background edge in them (I wouldn't recommend this, since it's kind of a hack).Another way to do it would be to create a second tilemap to just hold your pieces that you could put over top of your background tilemap.
A third approach would be to create your game pieces as independent sprite templates, and then you could create clones of them at the X,Y coordinates of the center of each tile.
Do any of those sound like they would help? I can go into more depth if any of those sound like something you want to do.
#13
Dan has some great suggestions. On my last tile puzzle game, Dan's option 2 ()multiple overlapping tilemaps worked out great for my needs.
John K.
10/20/2007 (3:52 pm)
Sorry for the duplicate posts... apparently I was hitting refresh to see new comments and accidently reposted the code. I've deleted the duplicates ;)Dan has some great suggestions. On my last tile puzzle game, Dan's option 2 ()multiple overlapping tilemaps worked out great for my needs.
John K.
#14
10/20/2007 (4:09 pm)
@Dan the third approach sound like the best way for me.
#15
10/20/2007 (4:13 pm)
Hey Danny I think the third approach would be best...I have put together a match 3 prototype in director but I hate using director...So I'm moving my game to TX too.
#16
10/20/2007 (5:09 pm)
@Danny - First, in TXB, give your tilemap a name in the Scripting rollout (I used "board" in my code below). Also, create sprites for each of your pieces, mark them as templates, and give them names (I used "gamepiece0" and "gamepiece1" in my code). Then, once you have that, you can do something like this:// set up the choices to match the names set on the templates in TXB.
string[] choices = { "gamepiece0", "gamepiece1" };
// get a reference to the background tilemap created in TXB.
T2DTileLayer Board = TorqueObjectDatabase.Instance.FindObject("board") as T2DTileLayer;
// now, count through every tile in the tile map and put a random game piece on it.
for (int i = 0; i < Board.MapSize.X; i++)
{
for (int j = 0; j < Board.MapSize.Y; j++)
{
// pick a random game piece.
int c = TorqueUtil.GetRandomInt(0, choices.Length);
string choice = choices[c];
// create a clone of the template, based on the random name we picked.
T2DSceneObject GamePiece = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>(choice);
// set the position of the object to the center of the tile we're looking at.
GamePiece.Position = Board.GetTileByGridCoords(i, j).GetWorldPosition(Board);
// register the new object.
TorqueObjectDatabase.Instance.Register(GamePiece);
}
}Does that make sense?
Associate John Kanalakis
EnvyGames
//get a reference to the tilemap T2DTileLayer tilemap = TorqueObjectDatabase.Instance.FindObject<T2DTileLayer>("MyTilemap"); //create an individual tile T2DTileObject tile = new T2DTileObject(); //create a tile type T2DTileType tileType = new T2DTileType(); //set the tile's properties - set the material by name tileType.Material = TorqueObjectDatabase.Instance.FindObject<GarageGames.Torque.Materials.RenderMaterial>("GGLogoMaterial"); tileType.Name = "Logo Tile"; //set the tile type to this tile tile.TileType = tileType; //set the four corners of the tilemap with this tile tilemap.SetTileByGridCoords(0, 0, tile); tilemap.SetTileByGridCoords(0, 7, tile); tilemap.SetTileByGridCoords(7, 0, tile); tilemap.SetTileByGridCoords(7, 7, tile);Essentially, you need to query the TorqueObjectDatabase (master of all things in the scene) to get a reference to the tilemap. Then, create one or more tiles, aka the T2DTileObject class. Then, the tile needs a T2DTileType that describes the tile. Then, go back to the TorqueObjectDatabase and get a hold of the registered material (example uses the stock GGLogoMaterial). Then apply the tile type to the tile. Once that's set, start painting your tile cells... remember that the tilemap grid is zero-based, so first position is 0 and the last position is 7. ;)
John K.