Game Development Community

Tile-by-tile movement

by Christopher McDonald · in Torque Game Builder · 02/05/2006 (1:54 pm) · 4 replies

I just bought T2D yesterday, and I've gone through the basic tutorial and done some of the strategy
tutorial. Now I'm trying to figure out how to do tile-by-tile movement, as in a game like
X-Com or Ultima. I have a box moving around on the map I created in the strategy controller, but it
isn't aligned with the tiles. It's moving 4 units at a time in each direction, as I expect, but it's not
moving from tile center to tile center.

Here's my code to create the map:

function LoadWorldMap()
{
$tilesize = 4;
new ScriptObject(worldMap);
worldMap.map = new t2dTileMap(Map) { scenegraph = $strategyScene; };
worldMap.map.loadTileMap("~/data/tilemaps/worldMap.map");

worldMap.grassLayer = addLayer(worldMap.map, 0);
worldMap.grassOverLayer = addLayer(worldMap.map, 1);

}

function addLayer(%map, %num)
{
%layer = %map.getTileLayer( %num );
%layer.setPosition( "0 0" );
%layer.setTileSize( $tilesize SPC $tilesize );
%layer.setLayer(30);
%layer.setGroup(10);

return %layer;
}

Here's the code to intialize a player:

function CreatePlayer()
{
$player = new t2dStaticSprite() { scenegraph = $strategyScene; };
$player.setPosition("-2 -2");
$player.setSize($tilesize SPC $tilesize);
$player.setImageMap(boxImageMap);
$player.speed = 4*$tilesize;

...
}

And here's one of my move functions (bound to 'w'):

function moveUp(%obj)
{
if (%obj.moving)
return;

%obj.moving = true;
%obj.moveTo(%obj.getPositionX() SPC (%obj.getPositionY() - $tilesize), %obj.speed,
true, true, true, 0.01);
}

Can anyone help me figure out what I'm doing wrong?

Thanks,
Chris

#1
02/05/2006 (6:32 pm)
Have any pics :) That would help me get an idea of what your running into
#2
02/06/2006 (4:37 pm)
Well, now that I look at it more carefully, I think it was working as I expected. My eyes were deceiving me, due to an artifact in the tile image I thought the edge was in a different place than where it actually was. But that does lead to a follow-up question, is there a shortcut or console command built into Torque to capture a screenshot?

Thanks,
Chris
#3
02/06/2006 (4:47 pm)
Ctrl P will take a screenshot

You can go to your options dialog and change it to either PNG or JPG :)
#4
02/06/2006 (5:01 pm)
Thanks!