|
Introduction
This is a simple component that creates a brick like breakable component seen in popular platformers
Download file
The zip contains three things:
-BrickComponent.cs
-GravityPepperCollectibleComponent.cs
-BrickAnimationStrip
link Download
Import Objects into game
If you just want a brick component then you don't need to import the pepper class.
Create two classes named: BrickComponent.cs and GravityPepperCollectibleComponent.cs and add the corresponding code into them. Copy and paste the image into you content folder. If you are using TXB import the image into the project, by creating a material calling it brickMaterial. Then create an animation spliting the image into 6 cells (38 x 45).
Create a brickComponent, by dragging the animation of the brick breaking into the level. Untick the boxes in the 'Animated Sprite'. Give it the 'BrickComponent' and 'SolidComponent' components. Set the animation in the 'BrickComponent' to the brick-breaking animation, you created earlier.
If you are adding GravityPeppers into the game you need to create a gravityPeperComponent in a similar way to the normal pepper. Making sure to mark it as a template. Also in the 'Scripting' tab of the pepper; set the name to 'gravitypeppertemplate'. Make sure to add the GravityComponent (EDIT by Zilla: and a T2DPhysicsComponent) too.
Creating gravity peppers
If you want to add gravity peppers. Uncomment these lines in the breakComponent's on OnAnimationEnd method
/*
* Uncomment these lines if you are planning to add the gravitypeppertemplate object when the OnAnimationEnd
*
T2DSceneObject pepper = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("gravitypeppertemplate");
if (pepper != null)
{
T2DSceneObject gravityPepper = (T2DSceneObject)pepper.Clone();
T2DSceneObject _owner = Owner as T2DSceneObject;
gravityPepper.Position = _owner.Position;
TorqueObjectDatabase.Instance.Register(gravityPepper);
}
*/
Conclusion
Please feel free to edit anything that you think could be more clearly explained.
The brick.png is pretty poor. If anyone wants to contribute, please feel free to upload your own brick to this page.
If anyone finds something that could be improved please us know!!
|