TX/T2DSceneObject

From TDN

This page is a Work In Progress.


Contents

Introduction


The main object in simple 2D games.

LinkPoints


Link point component for scene object, or null if it doesn't have one. Note: link point component is not cached on object, so this property causes a component lookup.
This code will return a LinkPointComponent.

T2DLinkPointComponent linkPoint = SceneObject.LinkPoints;

More information on T2DLinkPointComponent

Size


Syntax

public virtual Vector2 Size { get; set; }

The Size method allows you to resize the object including any CollisionPolygon and image attached to the object
Example
This examples half's the size of the T2DSceneObject. Where variable Owner is a TorqueObject.

((T2DSceneObject)Owner).Size = ((T2DSceneObject)Owner).Size / 2;

This example only half's the X value of the object

((T2DSceneObject)Owner).Size = new Vector2(((T2DSceneObject)Owner).Size.X / 2, ((T2DSceneObject)Owner).Size.Y);

VisibilityLevel


Syntax

public float VisibilityLevel { get; set; }

Sets alpha blend value to control the degree of visibility. If Visible property is false then object is not visible no matter what this value is. It takes values from 0 (invisible) to 1 (solid).
The image below shows how the visibility level affects how the scene object looks. The left image's visibility is set to 1 and the right to 0.5
Visibility levels
In order to get this property to work you need to make sure the material is translucent and allows colour blending.

In TXB

<SimpleMaterial name="GGLogoMaterial" type="GarageGames.Torque.Materials.SimpleMaterial">
            <TextureFilename>data/images/GGLogo.png</TextureFilename>
            <IsTranslucent>true</IsTranslucent>
            <IsColorBlended>true</IsColorBlended>
</SimpleMaterial>

In game code

T2DAnimatedSprite sceneObject = SceneObject as T2DAnimatedSprite;
SimpleMaterial _renderMaterial = sceneObject.AnimationData.Material as SimpleMaterial;
_renderMaterial.IsColorBlended = true;
_renderMaterial.IsTranslucent = true;

And then you just need to change the visibility level:

SceneObject.VisibilityLevel = 0.5f;

Note: If you are using the material as a particle, it seems to allow the visibility level to work without changing material properties. (It must change it when the game is running)

Visible


Syntax

public bool Visible { get; set; }

True if visible. Collisions are also disabled if not visible.
Note that the collision images are not removed. To remove the first T2DCollisionImage from the T2DSceneObject

private T2DCollisionImage _collisionImage;

protected override bool _OnRegister(TorqueObject owner)
{
ReadOnlyArray<T2DCollisionImage> images = myOwner.Collision.Images;
Assert.Fatal(images.Count > 0, "There are no T2DCollisionImages installed on this object");
_collisionImage = images[0];
}

protected void RemoveImage()
{
((T2DSceneObject)Owner).Collision.RemoveImage(_collisionImage);
}