Game Development Community

Tiles \ Sprites Positioning

by Bruno · in Torque Game Builder · 11/23/2005 (8:20 am) · 6 replies

Hi..,

I'm tryng to figure out how to work with this, but i'm not having much luck.
Ok, i'm using a tile layer with a "ghost" tile images.., i get the position of that tile trough onTileScript, and i feed the position to a function, like this :

function fxSceneObject2D::onTileScript( %this, %tLayObj, %tXY, %script )
{
 if( %script == 1) Some_Function(%tXY);

}

Then, in the function, i simply do this :

function Some_Function(%tXY)
{

 %x1 = getWord( %tXY, 0 );
 %y1 = getWord( %tXY, 1 );
 %obj.setPosition("60" SPC %y1);

}

One thing that i believe it's important is that the layer was setup like this :
%triggerLayer.setTileSize( "6 6" );

and the sprite was like this :
%obj.setSize( "20 20");


Anyways, the sprite doens't show up in the correct Y position, at first i tought it was some kind of offset problem with the sprite , so i adjusted the position manually, but while it works for one sprite/tile , it doens't work if i change the trigger tiles around in the tile layer.
So, there must be some kind of "formula", to apply in this ?
thanks,

Bruno

#1
11/23/2005 (8:51 am)
I don't know if this will help, but I was trying to do calculations based on the getPosition(),1 (the Y axis) and it was really screwy...

%projectile.Alt = getWord($player.getPosition(),1);

Then I realized that it's getting a decimal value... so instead of getting a rounded number ( -30 ) I was getting ( -30.0003 ) or something like that.

So, I used the mFloor function to get my rounded number. Then all was fine.

%projectile.Alt = mFloor(getWord($player.getPosition(),1));

-Tim
#2
11/23/2005 (11:15 am)
Thanks Tim
Unfortenly i don't think that will work, assuming by the way we place them in the editor ii think tiles positions are integer numbers.., but i'l give it a go :)
thanks again,

Bruno
#3
11/23/2005 (11:41 am)
Thanks Tim
Unfortenly i don't think that will work, assuming by the way we place them in the editor ii think tiles positions are integer numbers.., but i'l give it a go :)
thanks again,

Bruno
#4
11/23/2005 (2:18 pm)
Nope, doesn't work...,
Any more ideias ?

Bruno
#5
11/28/2005 (9:36 am)
The onTileScrpt callback is passing back the index x/y of the tile, in other words, the row and column on the tileLayer. fxSceneObject.setPosition is expecting a world position.

There's no automatic way that I know of (there have been some threads about this) to get the world position from the tile coords. There's been some talk, or at least expressed desire, to have this be a feature in the future.

One thing you can do is calculate (manually) the tileLayer's local pivot offset coords (within the "-1 -1" to "1 1" space), and then add a linkPoint at that location. Then you can do something like $tileLayer.getLinkPoint(%linkIndex).getPosition() - (I think this is how you do it... I know there's a way, I'll double check when I get back to my projects).

Don't get me wrong, this is kind of a pain. There doesn't seem to be a way to delete linkPoints either, although I think you can just keep resetting the same index, which will replace it.

Hope this helps
#6
11/30/2005 (2:44 am)
I've posted a little information on this thread.

- Melv.