T2dTileLayer Updates
by David Higgins · in Torque Game Builder · 02/14/2007 (10:11 am) · 3 replies
This code was moved from thid thread
You'll need to add the prototype to the t2dTileLayer.h in a public section, then just add the code below that to the source file at the bottom ... recompile, and it works like so:
This should allow for you to make a 'rule base' system for adding additional tiles to the map -- I wrote up some notes last night and jotted them down, cause this sounded like an interesting thing to work on ... here's the notes I have;
If you place a Con::executef(this, 1, "onTileSet"); at the bottom of the 'setStaticTile' method -- you could generate a TorqueScript callback informing you of a 'tile placed' ... with the XMLObject resource I did a few weeks back, and the modifications mentioned in this post, you should be able to script out a fairly quick and easy 'tile fixer upper' -- however, you may want to add an additional 'flag' to the tile layer object that tells it to 'ignore' the 'setStaticTile' callback as you'll most likely not want to have it do this 'all the time' -- such as when the tile layer is loaded, for example ... you'd want to disable it at that point ... so add another field to initPersistFields as well ...
You'll need to add the prototype to the t2dTileLayer.h in a public section, then just add the code below that to the source file at the bottom ... recompile, and it works like so:
%obj = layer.getStaticTile(3,4);
// OR
%obj2 = layer.getStaticTile("3 4");This should allow for you to make a 'rule base' system for adding additional tiles to the map -- I wrote up some notes last night and jotted them down, cause this sounded like an interesting thing to work on ... here's the notes I have;
Quote:
I figure a nice XML file would do just right --
For example -- so whenever frame "1" is placed from "tileImageMap", the 8 surrounding tiles are replaced with the respectful frames -- if the directional element is omitted, or the frame is "-1" then the tile is 'skipped'
This would best be done with a sub-classed 'Tile Layer' that overrides the default 'setTileData' (or whatever its called) method and then performs its magic -- the 'magic' could also generate TorqueScript callbacks, to allow for further 'per project' customizations in the 'logic'
If you place a Con::executef(this, 1, "onTileSet"); at the bottom of the 'setStaticTile' method -- you could generate a TorqueScript callback informing you of a 'tile placed' ... with the XMLObject resource I did a few weeks back, and the modifications mentioned in this post, you should be able to script out a fairly quick and easy 'tile fixer upper' -- however, you may want to add an additional 'flag' to the tile layer object that tells it to 'ignore' the 'setStaticTile' callback as you'll most likely not want to have it do this 'all the time' -- such as when the tile layer is loaded, for example ... you'd want to disable it at that point ... so add another field to initPersistFields as well ...
About the author
#2
02/15/2007 (12:26 am)
David, thanks for spelling all this out for me. I hope your solution ends up in the code base along with docs on how to format the rules document. :) Is there some news alert or RSS feed to subscribe to for when these kinds of features get included in TGB?
#3
I was actually thinking of making some form of a resource to make a 'warcraft ii' style map editor based on your thread ... but I've got so many other oddball things I'm working on, I had to write the idea down and put it on the bottom of the stack ... so I've no clue when I'll dig it back up ...
02/15/2007 (6:34 am)
@Darian, no -- but they usually announce TGB updates in the general store feed I believe -- and each update includes a "change log" of sorts... I was actually thinking of making some form of a resource to make a 'warcraft ii' style map editor based on your thread ... but I've got so many other oddball things I'm working on, I had to write the idea down and put it on the bottom of the stack ... so I've no clue when I'll dig it back up ...
Associate David Higgins
DPHCoders.com
t2dTileLayer.cc:
const bool t2dTileLayer::getStaticTileSceneObject(const U32 tileX, const U32 tileY, t2dStaticSprite *sprite) { t2dTileLayer::tTileObject* pTileObject; if(!getTileObject(tileX, tileY, &pTileObject)) return false; // problem if(!pTileObject) return false; // Empty Tile // TODO: Is this check worth it? Tile Nodes can be NULL? if(!pTileObject->mpTileNode) return false; // no Tile Node? Impossible? if(pTileObject->mpTileNode->mTileType != t2dTileMap::STATIC_TILE) return false; // not a Static Tile t2dTileMap::cStaticTileNode *node = (t2dTileMap::cStaticTileNode *)pTileObject->mpTileNode; if(!node) return false; // no node? if(!sprite) sprite = new t2dStaticSprite(); if(!sprite->registerObject()) { delete sprite; Con::errorf("Failed to register t2dStaticSprite"); return false; } sprite->setImageMap(node->pImageMapDataBlock2D->getName(), node->mFrame); const t2dVector tileSize = t2dVector(mTileSizeX, mTileSizeY); // force the size and position to match the tile sprite->setSize(tileSize); if(!sprite) return false; return true; } ConsoleMethod(t2dTileLayer, getStaticTile, const char*, 4, 6, "(x / y), (x / y) - Gets a t2dStaticSprite for the Current Static Tile") { // The tile. U32 tileX, tileY; U32 posX, posY; // TODO: Pass Start Position as 2 param (tile x/y == param 1) // Grab the element count. U32 elementCount = t2dSceneObject::getStringElementCount(argv[3]); // ("tileX tileY") if ((elementCount == 2) && (argc < 5)) { tileX = dAtoi(t2dSceneObject::getStringElement(argv[3], 0)); tileY = dAtoi(t2dSceneObject::getStringElement(argv[3], 1)); } // (tileX, tileY) else if ((elementCount == 1) && (argc > 4)) { tileX = dAtoi(argv[3]); tileY = dAtoi(argv[4]); } // Invalid else { Con::warnf("t2dTileLayer::getTileCollision() - Invalid number of parameters!"); return 0; } t2dStaticSprite *sprite = new t2dStaticSprite(); if(!object->getStaticTileSceneObject(tileX, tileY, sprite)) { return NULL; } else { return sprite->getIdString(); } }