OK now I need help with TileLayer object
by Rich Hudson · in Torque X 2D · 03/15/2009 (2:47 pm) · 8 replies
I am trying to emulate fog of war. Since when you assign a TileType to a Tile, and then change the material, ALL tiles will be updated with the new material, I have created 2 types per tile (each with a unique name), one solid and one translucent. That way I thought I could swap them out as needed. But when I swap in a Translucent TileType ANYWHERE in the TileLayer, all tiles STILL change to translucent!!!
I am wondering then if it really is TileType that sets this, or if the engine does a lookup on all materials associated with the tiles and changed them ALL???
Anyone know? Anyone successfully implemented fog of war as a tilelayer??
I am wondering then if it really is TileType that sets this, or if the engine does a lookup on all materials associated with the tiles and changed them ALL???
Anyone know? Anyone successfully implemented fog of war as a tilelayer??
#2
_fogOfWar.GetTileByGridCoords(0, 0).TileType = _fogOfWar.TileTypes[1];
where _fogOfWar is the tilemap. Soon as I change tile 0,0 they all change to TileTypes[1].
03/17/2009 (7:14 pm)
Yeah I would appreciate it, as thats what I am doing with the same effect (not working)._fogOfWar.GetTileByGridCoords(0, 0).TileType = _fogOfWar.TileTypes[1];
where _fogOfWar is the tilemap. Soon as I change tile 0,0 they all change to TileTypes[1].
#3
I put that exact line of code in my project in a ProcessTick method and the tile at 0,0 changes with no other problems. I even made it switch every time with this code and it just flickered on the screen, all other tiles stayed the same.
At first I thought maybe it was a pointer issue. Like since TileType was essentially _tileLayer.TileTypes[0], when you set it to TileTypes[1], you were actually setting TileTypes[0] to TileTypes[1]. I don't think this is happening since I'm not seeing the same issue, but you might want to put in a break statement to check that the two TileTypes are infact still different after the assignment.
The other thing you might want to try is making a new instance of a T2DTileType and assigning it, just to see if it works.
03/18/2009 (11:27 am)
Haha ah man Rich, things are just not going right eh?I put that exact line of code in my project in a ProcessTick method and the tile at 0,0 changes with no other problems. I even made it switch every time with this code and it just flickered on the screen, all other tiles stayed the same.
_odd = !_odd;
if (_odd)
{
_tileLayer.GetTileByGridCoords(0, 0).TileType = _tileLayer.TileTypes[2];
}
else
{
_tileLayer.GetTileByGridCoords(0, 0).TileType = _tileLayer.TileTypes[1];
}So I'm wondering if anywhere else in the code you are touching the TileTypes? Setting the Materials?At first I thought maybe it was a pointer issue. Like since TileType was essentially _tileLayer.TileTypes[0], when you set it to TileTypes[1], you were actually setting TileTypes[0] to TileTypes[1]. I don't think this is happening since I'm not seeing the same issue, but you might want to put in a break statement to check that the two TileTypes are infact still different after the assignment.
The other thing you might want to try is making a new instance of a T2DTileType and assigning it, just to see if it works.
T2DTileType newTileType = new T2DTileType(); newTileType.Material = _tileLayer.TileTypes[2].Material; _tileLayer.GetTileByGridCoords(0, 0).TileType = newTileType;
#4
03/22/2009 (7:50 pm)
OK its working Alex, thanks for the input. Not sure what was wrong with my code in the end. But I think SetTileByGridCoords might be broken, never thought to use GetTileByGridCoords(x,y).TileType, that did it.
#5
I am having this exact same problem and it is driving me crazy. How did you get it to stop changing all of your tiles when you changed the tile type??
Is there anyway I can see your code for this?
08/04/2009 (7:53 pm)
Rich, I know you said you were leaving the forums but I really hope you get this! I am having this exact same problem and it is driving me crazy. How did you get it to stop changing all of your tiles when you changed the tile type??
Is there anyway I can see your code for this?
#6
08/05/2009 (12:24 pm)
Luckily it came to my email. I will look at my old code tonight and see what I can find. However it seems to be that what I was doing (which didn't work) and what fixed it (Alex's code above) is layed out. But I will check for you.
#7
I threw the
_fogOfWar = TorqueObjectDatabase.Instance.FindObject<T2DTileLayer>("FogOfWar");
in there just so you could see what it is...does that help?
08/06/2009 (2:17 pm)
What I was doing is:private void ProcessFogOfWar()
{
_fogOfWar = TorqueObjectDatabase.Instance.FindObject<T2DTileLayer>("FogOfWar");
//Check tiles, if they are close to hero remove them
for (int row = 0; row < (int)_fogOfWar.MapSize.Y; row++)
{
for (int column = 0; column < (int)_fogOfWar.MapSize.X; column++)
{
T2DTileObject tile = _fogOfWar.GetTileByGridCoords(column, row);
Vector2 tilePos = tile.GetWorldPosition(new Vector2(0.0f, 0.0f), 0.0f, _fogOfWar.MapSize, _fogOfWar.TileSize);
if (tile.TileType != _fogOfWar.TileTypes[1])
{
if (Utils.Utilities.GetDistanceBetweenObjects(tilePos, Game.Instance.Hero.Position) < 50.0f)
{
_fogOfWar.GetTileByGridCoords(column, row).TileType = _fogOfWar.TileTypes[1];
}
}
}
}
}I threw the
_fogOfWar = TorqueObjectDatabase.Instance.FindObject<T2DTileLayer>("FogOfWar");
in there just so you could see what it is...does that help?
#8
But I will definitely review your code to see if I can figure out what I was doing wrong.
Again, thank you!
08/06/2009 (9:46 pm)
Thank you for getting back to me, Rich! You are a kind soul. I've found a way around this: http://www.garagegames.com/community/forums/viewthread/98805/1#comment_formBut I will definitely review your code to see if I can figure out what I was doing wrong.
Again, thank you!
Torque Owner Alex Stittle
Unfortunately I'm not at home right now so I don't have the code with me but the idea was to change the TileType, not TileType.Material. Although, it sounds like you are doing this already.
The code was something like:
When I get home I'll double check what exactly the code was and re-post.
- Alex
www.stinkerstudios.com