Dynamical created tile layer not visible [solved]
by Max Kielland · in Torque Game Builder · 01/17/2013 (2:19 am) · 4 replies
Hi,
I want to add a new tile layer to my existing TileMap and fill it with some random background tiles.
Here is some test code:
When inspecting the %layerCount variable I can see that a new layer is created and added to the %tileMap, but if I place a tile on the new tile layer it is not shown.
If I select the first layer (layer index 0) the tile shows up.
Do I have to do something to show the new layer on screen?
[EDIT]
There was some copy/paste errors in the test code.
I want to add a new tile layer to my existing TileMap and fill it with some random background tiles.
Here is some test code:
function FactoryTileMap::onLevelLoaded(%this) {
// Get gloab Tile Map
%tileMap = $LastLoadedScene.getGlobalTileMap();
// Check number of layers
%layerCount = %tileMap.getTileLayerCount();
// Create a new layer
%layer = %tileMap.createTileLayer("10 10","10 10");
// Check if the layer was created
%layerCount = %tileMap.getTileLayerCount();
// Get first layer
//%layer = %tileMap.getTileLayer(0);
// Place tile on layer
%layer.setStaticTile("4 3", "TileMapImageMap",9);
}When inspecting the %layerCount variable I can see that a new layer is created and added to the %tileMap, but if I place a tile on the new tile layer it is not shown.
If I select the first layer (layer index 0) the tile shows up.
Do I have to do something to show the new layer on screen?
[EDIT]
There was some copy/paste errors in the test code.
About the author
Owner of MK Development www.mkdevelopment.se
#2
I checked the visible value and it is already set to true after it has been created.
More ideas to try?
01/17/2013 (6:57 am)
No, it does nothing.I checked the visible value and it is already set to true after it has been created.
%visible = %layer.getVisible(); %layer.setVisible(true);
More ideas to try?
#3
The new tile layer's scene size was not updated to the bigger grid size I had. My test tile was draw outside the scene view.
The following row of code solved it:
So to create a background layer of randomly selected tiles I made this little snippet:
01/17/2013 (7:27 am)
Okay I solved it :)The new tile layer's scene size was not updated to the bigger grid size I had. My test tile was draw outside the scene view.
The following row of code solved it:
%layer.Size = "100 100";
So to create a background layer of randomly selected tiles I made this little snippet:
// Get global Tile Map
%tileMap = $LastLoadedScene.getGlobalTileMap();
// Create a new layer
%layer = %tileMap.createTileLayer("10 10","10 10");
%layer.Size = "100 100";
%layer.Layer = 20;
// Populate layer with tiles
for(%y=0; %y<%layer.getTileCountY(); %y++) {
for(%x=0; %x<%layer.getTileCountX(); %x++) {
%layer.setStaticTile(%x SPC %y, "TileMapImageMap",getRandom(0,9));
}
}
#4
01/17/2013 (9:35 am)
Sweet. Thanks for sharing - my idea was just a shot in the dark anyway; visibility for scene objects usually defaults to true....
Torque Owner Richard Ranft
Roostertail Games