Picking up Items
by Brian Wilmeth · in Torque Game Builder · 02/19/2006 (1:33 pm) · 16 replies
Here's what I want to do.
I want to make a map in the tile editor. Some tiles I want physics activated (walls), some tiles I want to be able to pick up (items). Is there a good tutorial to look at on this topic?
I want to make a map in the tile editor. Some tiles I want physics activated (walls), some tiles I want to be able to pick up (items). Is there a good tutorial to look at on this topic?
About the author
#2
02/19/2006 (6:10 pm)
How would I do that? Or is there any good tutorials to learn from?
#3
for( %a = 0; %a
{
%q = 0;
if( $tile[a].GetCustomData() == ITEM )
{
$item[%q] = new Datablock;
%q++;
}
}
I know its something like that but I don't know the documentation on it.
Like in the tile editor, I cant set the custom data of a tile unless I draw a tile there. But I would need to make that particular tile invisible when the item is picked up.
And I would need to make it so I can collide with this particular tile differently, such that I don't stop moving, so I would need to turn the physics off for that tile..
I'm lost, particularly cause I don't know ANYTHING..
Is there a tutorial on using tiles for different purposes, using script with the tile editor..
Oh and I don't know what the level editor is all about, is there any tutorials on that...
Thanks for reading my long post :)
02/19/2006 (6:17 pm)
I don't know how to loop through tilesfor( %a = 0; %a
%q = 0;
if( $tile[a].GetCustomData() == ITEM )
{
$item[%q] = new Datablock;
%q++;
}
}
I know its something like that but I don't know the documentation on it.
Like in the tile editor, I cant set the custom data of a tile unless I draw a tile there. But I would need to make that particular tile invisible when the item is picked up.
And I would need to make it so I can collide with this particular tile differently, such that I don't stop moving, so I would need to turn the physics off for that tile..
I'm lost, particularly cause I don't know ANYTHING..
Is there a tutorial on using tiles for different purposes, using script with the tile editor..
Oh and I don't know what the level editor is all about, is there any tutorials on that...
Thanks for reading my long post :)
#4
That's true that custom data needs a tile in order to work, I hadn't thought of that. You could create a "dummy" layer that sits on top of your main tile layer, place tiles on it where you want your powerups to spawn, and use those tiles' userdata. You could also use this layer for things like enemy spawn locations, level exits, etc. Then you only need to hide that extra layer at runtime with something like "%whateverlayer.setvisible(0);"
To loop through your tiles you need something like this:
02/19/2006 (7:47 pm)
I don't think there are any tutorials on the level builder. It's brand new, so there's not much on it yet. If you want to try it out (it makes this kind of task a ton easier) you just need to download it from your "my account" page. There's a reference pdf in the "documentation" folder that might help.That's true that custom data needs a tile in order to work, I hadn't thought of that. You could create a "dummy" layer that sits on top of your main tile layer, place tiles on it where you want your powerups to spawn, and use those tiles' userdata. You could also use this layer for things like enemy spawn locations, level exits, etc. Then you only need to hide that extra layer at runtime with something like "%whateverlayer.setvisible(0);"
To loop through your tiles you need something like this:
for(%y = 0; %y < getword(%layer.getTileCount(), 1); %y++)
{
for(%x = 0; %x < getword(%layer.getTileCount(), 0); %x++)
{
%data = %layer.getTileCustomData(%x SPC %y);
}
}
#5
I solved the power up problem like this..
I set the customData for each of my tiles to either
(nothing)
or
ITEM
..
Then in the onCollision function
if (tile.customData() == ITEM)
{
tile.clearTile(%tilePos);
//POWER UP
}
then I use the clearTile function to get rid of the tile, and I program in the power up stuff.
02/19/2006 (9:06 pm)
Thanks for the useful code :)..I solved the power up problem like this..
I set the customData for each of my tiles to either
(nothing)
or
ITEM
..
Then in the onCollision function
if (tile.customData() == ITEM)
{
tile.clearTile(%tilePos);
//POWER UP
}
then I use the clearTile function to get rid of the tile, and I program in the power up stuff.
#6
02/19/2006 (9:28 pm)
Cool, nice to see you got it to work.
#7
But the problem is that my powerup return collision Reponses, so when the player pickup golden coin for example is velocity change a little and that a real problem cause i deactive collision reponse physics and so on but none seem's working.
Now i put every Powerup on a new layer and i will probably parse all the tiles to change the direction of collision reponse ( from player => tile to tile => player) but again, i would like to see better solutions than parsing all the tiles...
02/21/2006 (1:40 pm)
I've more or less do the same trick but with the platform TDN example with much more control on it.But the problem is that my powerup return collision Reponses, so when the player pickup golden coin for example is velocity change a little and that a real problem cause i deactive collision reponse physics and so on but none seem's working.
Now i put every Powerup on a new layer and i will probably parse all the tiles to change the direction of collision reponse ( from player => tile to tile => player) but again, i would like to see better solutions than parsing all the tiles...
#8
02/21/2006 (6:57 pm)
Just a personal style suggestion, but why not make your power ups t2dsceneobjects instead of tiles?
#9
02/21/2006 (7:17 pm)
Because I wouldn't know exactly where to place them. When I use the tile editor, its easy to place the powerups in the correct place.
#10
02/21/2006 (7:25 pm)
Fair enough :) Glad you got a solution that worked out for you--but to pimp the level editor again, this is much easier now (placing objects in your level).
#11
*Stephen : Exellent :)
Where can we grab this modification ?
The "T2D Product" has changed in our Account ?
thanks
02/22/2006 (2:33 am)
Changing the direction of collision reponse with tiles bring a warning inside the game console. So it's not working... We obviously need to use sceneObjects...*Stephen : Exellent :)
Where can we grab this modification ?
The "T2D Product" has changed in our Account ?
thanks
#12
02/22/2006 (7:30 am)
Guess I need to learn the level editor.. SOMEONE WRITE A TUTORIAL :)
#13
This time i parse all the tiles and when there is the "goldenCoin" customData i change it into a Tigger erea... But this isn't a good solution. When my Trigger execute the "enterAction" T2D Crash... Probably because i use parameters inside my "enterAction" function.
So i think i have to remove these tile object and replace them by a prototyped GoldenCoin without collisionReponse. But this is a REAL MESS.
Does anybody could give me a clue on how a player can pickup powerUp WITHOUT this dumb collisionReponse ?
thanks...
02/23/2006 (1:17 pm)
I'm always trying to kill the collisionReponse with tiles...This time i parse all the tiles and when there is the "goldenCoin" customData i change it into a Tigger erea... But this isn't a good solution. When my Trigger execute the "enterAction" T2D Crash... Probably because i use parameters inside my "enterAction" function.
So i think i have to remove these tile object and replace them by a prototyped GoldenCoin without collisionReponse. But this is a REAL MESS.
Does anybody could give me a clue on how a player can pickup powerUp WITHOUT this dumb collisionReponse ?
thanks...
#14
I'd still like the onCollision call back to be called. But I don't want the player to stop when he hits the object.
02/26/2006 (8:15 am)
Yeah I'd be interested in knowing how to do this too.I'd still like the onCollision call back to be called. But I don't want the player to stop when he hits the object.
#15
02/26/2006 (11:51 am)
You can set collisionActive (to get callbacks) while collisionPhysics are disabled...
#16
I want to enable physics for walls.
And disable it for other things, like coins.
02/26/2006 (2:21 pm)
Yes but it needs to be enabled for other things, like walls.I want to enable physics for walls.
And disable it for other things, like coins.
Torque Owner Drew Hitchcock
One way to make your tilemap without the items in it. When you're making the map set the "custom data" for the tiles where you want items to spawn to some value. Then, once the level is loaded in your game, loop through the tiles and spawn an item (t2dStaticSprite or t2dAnimatedSprite probably) on every tile that has custom data set equal to that value. You could also use the "script" field to do something similar.
The other way is to use the new level builder. Make your tilemap in the tilemap editor, place it into the level, then hand place the items with the level builder's tools.