TX/Tutorials and Guides/TX UserGuide/T2D and T2DComponents

From TDN

This page is a Work In Progress.

Contents


Return To Contents Page

Introduction

Torque X provides a 2D game system based on the popular Torque Game Builder game engine (TGB). We've modified the TGB engine by adding the concept of components and breaking much of the functionality of the TGB classes into several components.

T2DSceneObject

T2DSceneObject is the base class for all T2D objects. This class is derived from TorqueObject (so it can have components) and implements everything needed to be in the 2D scene graph. T2DSceneObject's can also be mounted to other T2DSceneObjects. A simple T2DSceneObject without any components added and not mounted to anything will neither render, move, or collide, it will simply sit in the scene graph. By adding various components you can affect it's behavior.

T2DStaticSprite

T2DStaticSprite is derived from T2DSceneObject but adds the ability to render a static sprite. A T2DSceneObject holds a reference to an existing RenderMaterial.

T2DAnimatedSprite

T2DAnimatedSprite is derived from T2DSceneObject but adds the ability to render an animated sprite (a sequence of frames).

T2DPhysicsComponent

If you add this component to a T2DSceneObject it will have the ability to simulate physics for the object. The physics component adds velocity and angular velocity properties to the object as well as mass and rotational inertia (moment of inertia). It works in concert with the T2DCollisionComponent, T2DForceComponent, and T2DWorldLimitComponent but can function without any of them.

T2DCollisionComponent

This component adds the ability to collide with other objects. You can install any number of collision images on the component (when moving each collision image is tested against the scene, so your "effective" image is the union of all your collision images). At this time, only the polygon collision image is defined, but eventually elliptical collision images will be added and you can always add your own types of collisions. The T2DCollisionComponent works in concert with the T2DPhysicsComponent to support physics simulation. However, the collision component can operate without the physics component (but you will have to drive movement yourself and call into the collision component on your own -- see the TestMoveTo method). The T2DCollisionComponent also allows you to specify how you want to respond to collisions (bounce off objects with no rotation, full rigid body collisions, "sticky" collisions, etc).

T2DWorldLimitComponent

If you add this component you will get notification when you collide with a world limit which you specify on the component. This is a very convenient way of specifying bounds on the world for your game. You will get an OnWorldLimit callback if you hit the world boundary and can also specify a collision resolution delegate (bounce, sticky, clamp, rigid, etc) just like you can for physical collisions.

T2DForceComponent

If you add this component you will have the ability to add arbitrary forces to your object. There are several types of forces that can be added (force types are: Force, MasslessForce, DragForce, DragForceDirectional, and DragForceBidirectional. Any number of forces can be added and removed during the course of the game. You can also control the strength of given forces, allowing the player to control, for example, the thrust of a space ship or the acceleration of a car.

T2DLinkPointComponent

This component allows the object to hold link points for mounting scene objects, forces, or deciding where a projectile should be launched from. The mount point can be changed over the course of the game in order to provide dynamic control over mounted objects, forces, etc.

T2DAnimationComponent

This component allows you to animate float interfaces on the object. Any variable that is exposed as a float interface can be animated using this component by simply providing the name of the interface and providing an animation curve. There are quite a few potential applications for this. For example, one can animate the rotation of a link point (rotation of every link point is exposed as a float interface using the name of the link point). This could be used to rotate a mounted object. It could also be used to control the direction of a force, allowing you to easily create things like balloons blowing out air and moving erratically. T2DSceneObjects also expose the alpha used for blending as "alpha", and this can be animated.

T2DProcessComponent

The process component allows you to hook into the process tick to perform simple computations on single float interfaces. The most important application of this is to process moves. Instead of writing a desiginated player control object for each game object, you can simply add process nodes to the process component which will map move elements onto particular float variables. For example, a simple car can be created by hooking up the stick to control the rotation of the front wheels (which have lateral drag forces associated with them) and hooking the trigger up to the strength of the acceleration force. The car will now be controllable with no special coding required.


Return To Contents Page

This is Community Maintained, you may, and probably will, find out of date material. Feel free to update any of these articles yourself.