Game Development Community

Tile Map Collisions

by Anthony Rosenbaum · in Torque Game Builder · 03/01/2005 (2:43 pm) · 7 replies

Now I had this working in a beta build, but I hadn't had the editor. So this is my first drawn Tilemap.

I made some tiles with collision turned on, basically some platforms.
I saved it, and loaded it my game.
I assign the bottom layer ( the only one I belive I made) to it's proper layer and group for collision.
$Level = new fxTileMap2D() { scenegraph = t2dSceneGraph; };
	$Level.loadTileMap("~/client/maps/Test.txt");
	$LevelLayer = $Level.getTileLayer( 0 );
    $LevelLayer.setPosition( "0 -50" );
    $LevelLayer.setGroup( 1 );
    $LevelLayer.setLayer( 10 );
    $LevelLayer.nameTag = "tileLayer";

I set up a player
$player= new fxAnimatedSprite2d();
    $player.addToScene(t2dSceneGraph);
    $player.playAnimation(StandAnimation);
    $player.setSize("16 16");
    $player.setPosition("0 0");
    $player.setCollisionActive(true,true);
    $player.setCollisionCallback(true);
    $player.setCollisionPolyPrimitive(8);
    $player.setEnabled(true);
   	$player.setGroup( 1 );
	$player.setLayer( 10 );
	$player.setCollisionMasks(BIT(1), BIT(10) );
	$player.nameTag = "player";
    sceneWindow2D.mount($player, "0 0", 1);


I see both the collision for my player and the tiles.

t2dSceneGraph.setDebugOn(bit(5));
As you can See
www.afterschoolcartoons.com/pres/lore2d.pngBut when I collide I don't get a call back.
function fxSceneObject2D::onCollision(%sent, %recieved, %srcRef, %dstRef, %colTime, %colNorm, %contactCount, %contactPoints){
echo(%sent.nameTag @ " collide with " @%recieved.nameTag SPC %srcRef SPC %dstRef SPC %colTime SPC %colNorm SPC %contactCount SPC %contactPoints);
 }

#1
03/01/2005 (4:18 pm)
Shouldn't you be checking for collision on the fxAnimatedSprite2d ?
#2
03/01/2005 (4:22 pm)
Tried it and no good, everything is sceneObject2d derived so it does work with other sprite collision just not the tiles
#3
03/01/2005 (6:02 pm)
You forgot to (or didn't show) set collisions properties for the tile layer itself
#4
03/02/2005 (2:49 am)
@Anthony: The tiles have individual options for collisions but you still need to turn the collisions on for the tile-layer itself using "setCollisionActive". This seems like duplication as you've already configured your tiles but this allows you to globally turn the collisions on/off without having to reconfigure the individual tiles.

I think this is what Drew was referring to.

- Melv.
#5
03/02/2005 (5:10 am)
That did it
#6
03/02/2005 (5:24 am)
Cool. One potential off the list. :)

- Melv.
#7
03/02/2005 (6:59 pm)
Quote:
I think this is what Drew was referring to.
Yes indeedy, sorry for not being more specific :)