Need a little help TGB 1.7.5
by Harrison Brock · in Torque Game Builder · 05/22/2010 (7:13 pm) · 2 replies
I have a tile map with the class name Board
and I have this code
The problem is with this part:
When I run the game..The console says something like "not able to find function getTileGridPosition"
Could someone help me with this?
and I have this code
function Board::onLevelLoaded(%this, %scenegraph)
{
$GridGraph = %this.getSceneGraph();
%this.xCount = %this.getTileCountX();
%this.yCount = %this.getTileCountY();
if( !isObject( gamepice ) )
{
error("Requires prototype piece called 'gamepicet' to clone");
return;
}
for(%a = 0; %a < %this.xCount; %a++)
{
for(%b = 0; %b < %this.yCount; %b++)
{
%this.pieces[%a,%b] = gamepice.clone(true);
%this.pieces[%a,%b].board = %this;
//set the position of the piece relative to the tile layer
%this.pieces[%a,%b].setPosition(%this.getTileGridPosition(%a, %b));
//set the size
%this.pieces[%a,%b].setSize(%this.getTileSize());
//is clickable!
%this.pieces[%a,%b].setUseMouseEvents(true);
}
}
}The problem is with this part:
//set the position of the piece relative to the tile layer %this.pieces[%a,%b].setPosition(%this.getTileGridPosition(%a, %b));
When I run the game..The console says something like "not able to find function getTileGridPosition"
Could someone help me with this?
About the author
Torque Owner Patrick W
Dream. Build. Repeat.
It looks like you're using the Match 3 example from TDN???
getTileGridPosition is not a built in TGB function, you have to create yourself with the namespace that you are using... In your case, "Board".
From the tutorial page:
//----------------------------------------------------------------------------------------- //Private Methods //----------------------------------------------------------------------------------------- function Board::getTileGridPosition(%this, %x, %y) { // grab the Board layer's position %tileMapPos = %this.getPosition(); // divide the position up into x and y variables %tileMapPosX = getWord(%tileMapPos, 0); %tileMapPosY = getWord(%tileMapPos, 1); // grab the Board layer's size %tileMapSize = %this.getSize(); // divide the size up into x and y variables %tileMapSizeX = getWord(%tileMapSize, 0); %tilemapSizeY = getWord(%tileMapSize, 1); // calculate the start position %tileMapStartX = %tileMapPosX - (%tileMapSizeX / 2); %tileMapStartY = %tileMapPosY - (%tileMapSizeY / 2); // currently size set to 6, 6 %tS = %this.getTileSize(); // calculate the position and pass it back %pos = (%tileMapStartX + (%x * %tS)) + %tS/2 SPC (%tileMapStartY + (%y * %tS)) + %tS/2; return %pos; } //called when a new gem has been placed function Board::resize(%this) { for (%i = 0; %i < %this.getTileCountX(); %i++) { for (%j = 0; %j < %this.getTileCountY(); %j++) { if(%this.pieces[%i,%j].getSizeX() < "6") { %this.pieces[%i,%j].setSizeX(%this.pieces[%i,%j].getSizeX() + 0.2); %this.pieces[%i,%j].setSizeY(%this.pieces[%i,%j].getSizeY() + 0.2); %this.schedule(10,resize); } } } }capiche?
Patrick