Trouble loading t2dTileLayer
by Darius · in Torque Game Builder · 03/10/2009 (9:35 pm) · 7 replies
I'm trying to load a tile layer from a file in code, and having some problems with it. I'm hoping someone can point out what I'm doing wrong. Here's my code:
I tried that, and it just doesn't load the file, I also tried this:
To no effect. I'm wondering if I'm trying to load from the wrong directory, but I've tried several different directory paths. I can load the file up in the editor, but it just isn't working for me in code.
Any help would be greatly appreciated. Thanks.
%streetLayer = new t2dTileLayer() {
LayerFile = "~/data/tilemaps/emptyLayer.lyr";
class = "streetClass";
UseMouseEvents = "1";
layer = $STREET_LAYER;
};
%streetLayer.resizeLayer(%xSize SPC %ySize);
%streetLayer.setTileSize($TILE_SIZE,$TILE_SIZE);I tried that, and it just doesn't load the file, I also tried this:
%streetLayer = new t2dTileLayer();
%streetLayer.loadTileLayer("~/data/tilemaps/emptyLayer.lyr");To no effect. I'm wondering if I'm trying to load from the wrong directory, but I've tried several different directory paths. I can load the file up in the editor, but it just isn't working for me in code.
Any help would be greatly appreciated. Thanks.
#2
I asked about the rationale for this in another thread (http://www.garagegames.com/community/forums/viewthread/86745) but got zero replies. Wish I could help more.
03/14/2009 (9:44 pm)
I don't understand this fully myself Darius. I was trying to figure out the onCollision callback and why it wasn't working for my own class. The only work around I found was using t2dTileLayer::onCollision, which to me would seem to be problematic if you had multiple tile layers and you wanted to ascribe different behavior to them all.I asked about the rationale for this in another thread (http://www.garagegames.com/community/forums/viewthread/86745) but got zero replies. Wish I could help more.
#3
I have add similar problems with static sprites.
@Aaron - I don't know if this will help but it is useful if you are going to be doing a lot of mouseEvents with different overlapping objects. www.garagegames.com/community/forums/viewthread/77324 Darius you might want to check it out too
03/14/2009 (10:20 pm)
@Darius - try applying the useMouseEvents after you load the layer. %streetLayer = new t2dTileLayer() {
class = "streetClass";
UseMouseEvents = "1";
};
$mapManager::tileMap.addTileLayer(%streetLayer);
%streetLayer.loadTileLayer("~/data/tilemaps/emptyLayer.lyr");
%streetLayer.setUseMouseEvents(true);I have add similar problems with static sprites.
@Aaron - I don't know if this will help but it is useful if you are going to be doing a lot of mouseEvents with different overlapping objects. www.garagegames.com/community/forums/viewthread/77324 Darius you might want to check it out too
#4
It worked, but it still seems like a screwy way of getting around things.
03/17/2009 (8:22 pm)
Thanks for the suggestions. What I ended up doing was changing the mouse events flag and the class name in the gui, then saving it to the tile layer I was trying to load.It worked, but it still seems like a screwy way of getting around things.
#5
Where are you defining $mapManager and what is the purpose of doing $mapManager::tileMap ?
03/21/2009 (6:59 pm)
I'm having a similar problem (TGB 1.7.4 on Windows XP). If I try something just like this:%streetLayer = new t2dTileLayer() {
class = "streetClass";
UseMouseEvents = "1";
};
$mapManager::tileMap.addTileLayer(%streetLayer);
%streetLayer.loadTileLayer("~/data/tilemaps/emptyLayer.lyr");Then it tells me $mapManager::tileMap isn't a tilemap. So then I try something like this:$mapManager = new t2dTileMap();
%streetLayer = new t2dTileLayer() {
class = "streetClass";
UseMouseEvents = "1";
};
$mapManager.addTileLayer(%streetLayer);
%streetLayer.loadTileLayer("~/data/tilemaps/emptyLayer.lyr");And TGB crashes when it runs the $mapManager.addTileLayer(%streetLayer); line.Where are you defining $mapManager and what is the purpose of doing $mapManager::tileMap ?
#6
When you define a t2dTileMap() you need to give it a scenegraph, otherwise it will crash when you try to add a tile layer, I'm not sure why though. You could do something like this:
That should take care of your crashing problem.
03/21/2009 (7:53 pm)
$mapManager is just a namespace for a set of variables, if you look at the script style guide, it recommends declaring global variables with a namespace prefix specifying a class or module that the global variable is related to. I could just as easily have called the variable $tileMap instead of $mapManager::tileMap.When you define a t2dTileMap() you need to give it a scenegraph, otherwise it will crash when you try to add a tile layer, I'm not sure why though. You could do something like this:
$mapManager = new t2dTileMap(){
scenegraph = sceneWindow2D.getSceneGraph();
};That should take care of your crashing problem.
#7
03/21/2009 (8:42 pm)
Thank you Darius, both for explaining the crash problem and pointing me to that script style guide.
Torque 3D Owner Darius
%streetLayer = new t2dTileLayer() { class = "streetClass"; UseMouseEvents = "1"; }; $mapManager::tileMap.addTileLayer(%streetLayer); %streetLayer.loadTileLayer("~/data/tilemaps/emptyLayer.lyr");And the code for my mouse event handler looks like this:
function streetClass::onMouseDown(%this,%modifier,%worldPosition,%clicks) { echo("street clicked on."); ... }That never get's called, at least I don't see the echo. Again, any help would be appreciated. Thanks.