-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Sprite Guide
All scene objects are known engine types that allow instances to be created at runtime. The "Sprite" is slightly different from other game type classes. It is derived from a parent type called "SpriteBase", which itself is derived from "SceneObject". That means it includes all the fields from those types as well as adding its own fields specific to itself.
A Sprite is simply a two dimensional image or animation that can be placed within a scene. Since the actual image rendering properties are inherited from SpriteBase and all collision and physics properties from SceneObject, there are actually only a couple fields and methods that belong to the Sprite itself. Nevertheless, a Sprite is one of the most commonly used objects within a scene.
The Sprite type exposes the following fields in addition to those it inherits. Shown are the equivalent methods available that perform the same action in setting and getting the respective field:
- FlipX
- setFlipX(bool)
- getFlipX()
- FlipY
- setFlipY(bool)
- getFlipY()
The following is a complete description of each of these fields.
Sets whether the image texture is flipped horizontally or not. The default is false.
%object = new Sprite();
%object.FlipX = true;
This field sets whether the image texture is flipped vertically or not. The default is false.
Using TorqueScript and the exposed fields or methods described in the previous section, you can programmatically create and configure a Sprite. You can then export this type to a TAML file or even create a TAML file manually and read it into your game at an appropriate time.
Here is an example Sprite TAML file in XML format:
<Sprite
SceneLayer="31"
Size="100 75"
BodyType="Static"
BlendColor="SlateGray"
Image="@asset=ToyAssets:highlightBackground"
Frame="0" />
The same example in JSON format:
{
"Sprite": {
"SceneLayer": "31",
"Size": "100 75",
"BodyType": "Static",
"BlendColor": "SlateGray",
"Image": "@asset=ToyAssets:highlightBackground",
"Frame": "0"
}
}
The following methods are available to further configure and control a Sprite.
Sets the sprite texture flipping status for each axis.
Gets the flip status for each axis.