Missing something: can't collide with a TileLayer
by 0x336699 · in Torque Game Builder · 03/14/2005 (11:40 pm) · 7 replies
Okay I know I'm doing something just dumb. Maybe someone here can see it. I have a simple TileMap with one layer. I have StaticSprites that can collide with each other just fine. But I can't for the life of me get a TileLayer from the TileMap and the sprites to collide with each other.
I've turned on collision boxes in debug mode and verified that the tiles are collidable. I've made sure to set everything's group and layer mask to 0xffffff, respectively. See for yourself:
setup code for my TileMap
setup code for my sprites
huh?

I've turned on collision boxes in debug mode and verified that the tiles are collidable. I've made sure to set everything's group and layer mask to 0xffffff, respectively. See for yourself:
setup code for my TileMap
%testMap = new fxTileMap2D() {scenegraph = t2dSceneGraph;};
%testMap.loadTileMap("~/client/maps/test.map");
%layer = %testMap.getTileLayer(0);
%layer.setPosition("0 192");
%layer.setTileSize("32 32");
%layer.setCollisionActive(false, true);
%layer.setCollisionPhysics(true, true);
%layer.setCollisionMasks(0xffffff, 0xffffff);setup code for my sprites
function Block::init(%this, %pos)
{
%this.sprite = new fxStaticSprite2D()
{
scenegraph = t2dSceneGraph;
};
%this.sprite.setImageMap(yellowBlockImageMap);
%this.sprite.setSize("32 32");
%this.sprite.setPosition(%pos);
%this.sprite.setCollisionActive(true, true);
%this.sprite.setCollisionPhysics(true, true);
%this.sprite.setCollisionMasks(0xffffff, 0xffffff);
%this.sprite.setCollisionMaterial(blockMaterial);
}huh?

#2
One difference I can see, is that I have set the group and rendering layer for the wall layer that I want to receive collisions. Also if your using the engines physics then I think you'll need to setup a collision material for your sprite and tile layer.
edit: Code layout is a little off due to wrapping on the forums post :(
03/15/2005 (3:51 am)
This is how I setup my tile layer for collisions:%this.levelMap = new fxTileMap2D( masterTileMap ) { sceneGraph = t2dSceneGraph; };
%this.levelMap.loadTileMap( "~/client/maps/level1.map" );
// set the loaded layer positions and sizes (can this be defaulted somehow?)
%layer = %this.levelMap.getTileLayer($Game::map::BLANK_MAP_LAYER);
%layer.setPosition( "0 0" ); // world center
%layer.setTileSize( $Game::map::TILE_SIZE );
%layer.setWrap( false, false );
%layer = %this.levelMap.getTileLayer($Game::map::WALL_MAP_LAYER);
%layer.setPosition( "0 0" );
%layer.setTileSize( $Game::map::TILE_SIZE );
%layer.setWrap( false, false );
//setup default collision handling for the wall layer
//we're setting the entire maps defaults for now, but later will do this per layer
%layer.setLayer( $Game::rendering::WALL_LAYER );
%layer.setGroup( $Game::collisions::WALL_GROUP );
%layer.setCollisionMaterial( immovableMaterial );
%layer.setCollisionActive( false, true );
%layer.setCollisionCallback( true );
%layer.setCollisionMasks( BIT( $Game::collisions::PLAYER_GROUP ),
BIT( $Game::rendering::PLAYER_LAYER ) );
%layer.setCollisionPhysics(false, false); // doing our own physics
//%layer.SetDebugOn(BIT(5));
%this._ParseMapInfo( %this );One difference I can see, is that I have set the group and rendering layer for the wall layer that I want to receive collisions. Also if your using the engines physics then I think you'll need to setup a collision material for your sprite and tile layer.
edit: Code layout is a little off due to wrapping on the forums post :(
#3
If your tiles are in group 2 and the player in group 1, set the players collision mask to BIT(2), BIT(2) and the tiles collision mask to BIT(1), BIT(1).
That might be the problem, but I'm still much to green with regards to t2d to be certain. But it might be worth a try.
03/15/2005 (3:59 am)
I think the problem is that you need to set the collision masks for your tiles and sprites. If your tiles are in group 2 and the player in group 1, set the players collision mask to BIT(2), BIT(2) and the tiles collision mask to BIT(1), BIT(1).
That might be the problem, but I'm still much to green with regards to t2d to be certain. But it might be worth a try.
#4
Alternativly you could set the masks to 0xFFFFFFFF (8 f's not 6) which should enable collisions with everything. Although I've not tried it, so I could be wrong :P
03/15/2005 (4:43 am)
Another thing to note is that you havn't set the players Group nor layer. You would need to set the group of your player and layer to 0xffffff if you wanted it to collide with your current layer masks.Alternativly you could set the masks to 0xFFFFFFFF (8 f's not 6) which should enable collisions with everything. Although I've not tried it, so I could be wrong :P
#5
BIT(number) command and using a layer number.
however you don't need to set
"%layer.setCollisionMasks(0xffffff, 0xffffff);"
considering the tile layer isn't moving and the source object is the object moving... and I have the collision material set in the tilemap editor so I don't set it in script and mine works fine...
note: setting collision mask to "0xFFFFFFFF" seemingly works :)
03/15/2005 (9:25 am)
When using "0xffffff" my test that works using simply layer numbers doesn't work... so I'd recommend using the standard BIT(number) command and using a layer number.
however you don't need to set
"%layer.setCollisionMasks(0xffffff, 0xffffff);"
considering the tile layer isn't moving and the source object is the object moving... and I have the collision material set in the tilemap editor so I don't set it in script and mine works fine...
note: setting collision mask to "0xFFFFFFFF" seemingly works :)
#6
Gary's last post also clued me in that the business with setting the group and layer to 0xffffff wouldn't have done what I intended (collide with everything) because you need to use 8 F's anyway.
Thanks again!
03/15/2005 (9:43 am)
Thanks, everyone, for your help. The problem was that I wasn't calling setLayer for either the TileLayer or the StaticSprites, as Gary pointed out.Gary's last post also clued me in that the business with setting the group and layer to 0xffffff wouldn't have done what I intended (collide with everything) because you need to use 8 F's anyway.
Thanks again!
#7
I'm thinking I might define some global like "$ALLBITS" or "$ALLMASK" to equal "0XFFFFFFFF" so this mistake becomes less common. You could, of course, do that in the meantime.
- Melv.
03/15/2005 (10:07 am)
Glad you got it working. :)I'm thinking I might define some global like "$ALLBITS" or "$ALLMASK" to equal "0XFFFFFFFF" so this mistake becomes less common. You could, of course, do that in the meantime.
- Melv.
Torque Owner Chris