Breakout style gameplay with a Tile layer
by Arden · in Torque X 2D · 11/12/2010 (4:22 pm) · 3 replies
Hiya all,
I'm wondering if there's a simple way to do this.
I'm trying to setup a simple tile map that contains different types of materials that can be destroyed by a ball. I tried with using sprites instead of tiles, but there are just too many and it's just not viable performance wise. Here is specifically what I want to accomplish:
- Fire the Oncollision delegate as soon as a tile is hit.
- Check the nature of the material for the specific tile (for various tests within the component for the tilemap for different outcomes)
- If the material is a certain ID, delete it at the specific tile that trigerred the collision.
So far, I have created the Tilemap, set the collisions for the tiles it contains and associated a component to the Oncollision delegate.
In the component, I have code that is supposed to fire-up when the on collision happens (but if I put a breakpoint there, it does not event happen):
Any ideas if I'm going the right way about it, and if anyone knows what would be missing in my code for it to work?
Anyways, thanks if anyone can help!
I'm wondering if there's a simple way to do this.
I'm trying to setup a simple tile map that contains different types of materials that can be destroyed by a ball. I tried with using sprites instead of tiles, but there are just too many and it's just not viable performance wise. Here is specifically what I want to accomplish:
- Fire the Oncollision delegate as soon as a tile is hit.
- Check the nature of the material for the specific tile (for various tests within the component for the tilemap for different outcomes)
- If the material is a certain ID, delete it at the specific tile that trigerred the collision.
So far, I have created the Tilemap, set the collisions for the tiles it contains and associated a component to the Oncollision delegate.
In the component, I have code that is supposed to fire-up when the on collision happens (but if I put a breakpoint there, it does not event happen):
public static void OnCollision(T2DSceneObject theirObject, T2DSceneObject ourObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
// Create an instance of the Tile for code manipulation
T2DTileLayer tilemap = TorqueObjectDatabase.Instance.FindObject<T2DTileLayer>("MainTilemap");
// Return the specific tile located at the Ball's coordonates
T2DTileObject myTile = tilemap.PickTile(theirObject.Position);
// Looking for the rest of the code to test out the material and set the material...
}Any ideas if I'm going the right way about it, and if anyone knows what would be missing in my code for it to work?
Anyways, thanks if anyone can help!
#2
11/12/2010 (4:42 pm)
Well that is the problem, I have a large number of tiny ones. My aim is to create a gate behind the paddle of each player. Each time the gate is hit a piece is chipped away. I need a good resolution for that (there are four gates for a total of about 1440 pieces) so having that many sprites on screen does affect the performance. So I'm looking for an alternative, where I can manage it through code and decompose a large object in smaller pieces as it is being hit.
#3
I tried using current player coordonates when the collision occurs, but since it's a X,Y positional vector, I'd need to convert it to the Grid and then make a calculation for the current velocity angle so I know which tile to delete around the ball. Seems like a lot of work, especially if I have a more direct way of knowing which tile was hit.
Any ideas?
11/12/2010 (4:49 pm)
One thing I'd really like to know also is if it's possible to know through code which tile in the TileLayer was collided by a player object. I tried using current player coordonates when the collision occurs, but since it's a X,Y positional vector, I'd need to convert it to the Grid and then make a calculation for the current velocity angle so I know which tile to delete around the ball. Seems like a lot of work, especially if I have a more direct way of knowing which tile was hit.
Any ideas?
Torque Owner Duncan Colvin
for a breakout game? unless you have and awfully large number of tiny bricks it shouldn't be an issue.