Game Development Community

How to scan the tile?

by Swami Venkat · in Torque Game Builder · 06/13/2005 (12:01 am) · 9 replies

Is there a way to scan below the player sprite to check if there is any tile present or not in a particular layer of the map? i.e. given the co ordinates, is there a way to check if a tile exists or not in the layer?

I want my player to fall down if there isnt any tiles below him and am not using any physics...

About the author

Recent Threads


#1
06/15/2005 (10:07 am)
I know there is a way, but that's about it. I've got the same question so I'll ask again.

Here's what I've got. The player drives a tank around. The tank needs to slow down on sand or mud, etc. The player can change tanks so before he couldn't drive on lava now he can. Got it? So I want to check for all the tiles under the tank and see which one slows him down the most. I *think* I need the pickTile() function but I have no idea how to use it. If I put the X,Y location of a tile into it, what do I get out? A number? A string? How do I use picktile() for an area not just a point? I'm sure someone else has come across this sort of thing already. Changing your speed based on the tiles is a pretty comon thing in games.

I also have a problem with stopping the player when he runs into certain tiles. I know I could just use the collision stuff, but the player can change tanks and differnt tanks can drive on differnt tiles. (some tanks can drive in water some can not, etc.) So, any suggestions?

-Peter
#2
06/15/2005 (10:19 am)
Quote:stopping the player when he runs into certain tiles.

The new physics modes Melv had in his latest plans will make this much easier... though for now you can activate the collision callback and then do .setAtRest(); to the object to get it to stop on collision.
#3
06/15/2005 (10:48 am)
Alright, but I'll still have to turn collisions on and off for large numbers of tiles during game play. Is there a way I could put all of my lava tiles or water tiles into a group at start up and then turn them all on and off at once? And how do you check to see what tiles are under a sprite?
#4
06/15/2005 (11:02 am)
@Peter: Don't forget that you can have collisions on but you don't necessarily have to let T2D do any collision response e.g. turn off the physics with "setCollisionPhysics()" and just do a custom action in the "onCollision()" callback. You don't need to turn collisions off so collisions don't affect the physics.

Not to be blunt but did you read the reference documentation? ;) As it says, it returns the logical tile position. (0,0) is the top-left tile, (1,0) is the one to the right of it etc, the same coordinates you use when you're setting-up tiles. Passing in a world-position will check to see which tile (if any) is at that point only so if the top-left tile of your map was there it'd return "0 0". You can then use the calls such as "getTileType()" or "getTileScript()" or "getCustomData()" or any of the other interrogative functions to determine what it is you're on.

Again, don't forget that "setCollisionPhysics()" can be used to start/stop collisions from having an effect on the physics. Collision still happen and you get callbacks, it's just that T2D doesn't do anything else.

Hope this helps,

- Melv.
#5
06/15/2005 (11:12 am)
It helps quite a bit. Thanks for clearing that up for me. I did read the reference doc but I didn't get it. I guess I just needed someone to elaborate a little. Thanks!

-Peter
#6
06/15/2005 (11:29 am)
Pick Tile is really good. It works by passing it a WorldPosition. Ill try to look up my old tests of things like this.
#7
06/15/2005 (11:33 am)
No problem at all. I'm try to make this kind of thing much easier to deal with so it's getting better and better all the time.

- Melv.
#8
06/16/2005 (3:45 pm)
Oh, now that makes sense. I was actually pretty confused too when reading the documentation for tileMap and tileLayer. I think what confused me is that the T2D Reference.pdf entry for fxTileLayer2D says that it takes in tileX/tileY, shouldn't that be something like worldX/worldY?

Quote:Function:
pickTile() Picks a tile.

Parameter(s):
(int tileX / int tileY )

Details:
tileX/Y Selected Tile.
Returns the logical tile position (x / y) if valid else returns nothing. All rotation and panning is taken into account.

I guess I should elaborate on what I'm proposing the new entry to look like.

Quote:Function:
pickTile() Picks a tile.

Parameter(s):
(int worldX / int worldY )

Details:
tileX/tileY Selected Tile.
Returns the logical tile position (tileX / tileY) if valid else returns nothing. All rotation and panning is taken into account.

That way, all references to the logical tile position use the prefix tile, and world positions use world.

Edit: It's already been fixed? Awesome!
#9
06/17/2005 (6:12 am)
@Christopher,

Yes, that was a typo and was amended a while ago from this thread.

The documentation does now contain the reference as you suggest.

- Melv.