Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Class TSprite
Unit
CastleGLImages
Declaration
type TSprite = class(TObject)
Description
Sprite is an animation composed from frames arranged in rows and columns inside a single image. Frames are read from left to right and from top to bottom.
In the simple case, a sprite represents a single animation, and the frames are just in consecutive order.
With the help of "custom animations" feature, you can define many animations in a sprite. Each custom animation is an array of frames with corresponding frames duration. Frames can be in any order. It is valid to use some particural frame many times with different duration time.
Hierarchy
Overview
Methods
 |
constructor Create(const URL: string; const AFrames, AColumns, ARows: Cardinal; const ASmoothScaling: Boolean = True; const ATimeLoop: Boolean = True; const APlay: Boolean = False); |
 |
constructor CreateFrameSize(const AImage: TGLImage; const AFrames, AColumns, AFrameWidth, AFrameHeight: Cardinal; const ATimeLoop: Boolean = True; const APlay: Boolean = False); overload; |
 |
constructor CreateFrameSize(const URL: string; const AFrames, AColumns, AFrameWidth, AFrameHeight: Cardinal; const ASmoothScaling: Boolean = True; const ATimeLoop: Boolean = True; const APlay: Boolean = False); overload; |
 |
destructor Destroy; override; |
 |
procedure Update(const SecondsPassed: TFloatTime); |
 |
procedure Play; |
 |
procedure Stop; |
 |
procedure Pause; deprecated 'use Stop'; |
 |
procedure Draw; overload; |
 |
procedure Draw(const AX, AY: Single); overload; |
 |
procedure Draw(const AX, AY, DrawWidth, DrawHeight: Single); overload; |
 |
procedure Draw(const ScreenRectangle: TRectangle); overload; |
 |
procedure Draw(const ScreenRectangle: TFloatRectangle); overload; |
 |
procedure DrawFlipped(const ScreenRect: TRectangle; const FlipHorizontal, FlipVertical: boolean); overload; |
 |
procedure DrawFlipped(const ScreenRect: TFloatRectangle; const FlipHorizontal, FlipVertical: boolean); overload; |
 |
procedure Move(AX, AY: Integer; ARot: Single=0); |
 |
function AddAnimation(const AAnimation: TSpriteAnimation): Integer; overload; |
 |
function AddAnimation(const AnimationFrames: array of Cardinal): Integer; overload; |
 |
function AddSpriteAnimation(const AnimationFrames: array of TSpriteAnimationFrame): Integer; deprecated 'use AddAnimation'; |
 |
function SwitchToAnimation(const AAnimIndex: Integer; const ACustomFrame: Cardinal = 0): Boolean; |
 |
function Duration: TFloatTime; |
Properties
 |
property X: Integer read FX write FX; |
 |
property Y: Integer read FY write FY; |
 |
property Position: TVector2Integer read GetPosition write SetPosition; |
 |
property CenterX: Single read GetCenterX write SetCenterX default 0.5; |
 |
property CenterY: Single read GetCenterY write SetCenterY default 0.5; |
 |
property DrawingWidth: Cardinal read FDrawingWidth write FDrawingWidth; |
 |
property DrawingHeight: Cardinal read FDrawingHeight write FDrawingHeight; |
 |
property DrawRect: TRectangle read GetDrawRect write SetDrawRect; |
 |
property Center: TVector2 read GetCenter write SetCenter; |
 |
property Rotation: Single read GetRotation write SetRotation default 0; |
 |
property Frames: Cardinal read FFrames; |
 |
property FramesPerSecond: Single
read FFramesPerSecond write SetFramesPerSecond
default DefaultFramesPerSecond; |
 |
property Frame: Cardinal read FFrame write SetFrame; |
 |
property Playing: Boolean read FPlaying write FPlaying default False; |
 |
property TimeLoop: Boolean read FTimeLoop write FTimeLoop; |
 |
property Time: TFloatTime read FTime write SetTime; |
 |
property FrameWidth: Cardinal read FFrameWidth write FFrameWidth; |
 |
property FrameHeight: Cardinal read FFrameHeight write FFrameHeight; |
 |
property LeftMargin: Cardinal read FLeftMargin write FLeftMargin default 0; |
 |
property LeftMarginOffset: Cardinal read FLeftMargin write FLeftMargin default 0; deprecated 'use LeftMargin'; |
 |
property TopMargin: Cardinal read FTopMargin write FTopMargin default 0; |
 |
property TopMarginOffset: Cardinal read FTopMargin write FTopMargin default 0; deprecated 'use TopMargin'; |
 |
property HorizontalSpacing: Cardinal
read FHorizontalSpacing write FHorizontalSpacing default 0; |
 |
property VerticalSpacing: Cardinal
read FVerticalSpacing write FVerticalSpacing default 0; |
 |
property VerticalSpacingBottom: boolean
read FVerticalSpacingBottom write FVerticalSpacingBottom default false; |
 |
property TimeBackwards: Boolean read FTimeBackwards write FTimeBackwards default False; |
 |
property CurrentAnimation: Integer read FCurrentAnimation default -1; |
 |
property HorizontalFlip: Boolean read FHorizontalFlip write FHorizontalFlip default False; |
 |
property VerticalFlip: Boolean read FVerticalFlip write FVerticalFlip default False; |
 |
property DiagonalFlip: Boolean read FDiagonalFlip write FDiagonalFlip default False; |
Description
Methods
 |
constructor Create(const URL: string; const AFrames, AColumns, ARows: Cardinal; const ASmoothScaling: Boolean = True; const ATimeLoop: Boolean = True; const APlay: Boolean = False); |
Constructor.
Parameters
- URL
- URL of source image.
- AFrames
- Total numer of animation frames.
- AColumns
- Mumber of columns.
- ARows
- Number of rows.
- ASmoothscaling
- Enables interpolation, see TGLImageCore.SmoothScaling for details, default
True .
- ATimeLoop
- Should animation be repeated?, default
True .
- APlay
- Is animation playing? if not then current frame will be displayed.
|
 |
constructor CreateFrameSize(const AImage: TGLImage; const AFrames, AColumns, AFrameWidth, AFrameHeight: Cardinal; const ATimeLoop: Boolean = True; const APlay: Boolean = False); overload; |
Constructor that takes explicit frame size, and loaded TGLImage instance.
Parameters
- AImage
- Source image (will be owned by this sprite).
- AFrames
- Total numer of animation frames.
- AColumns
- Number of columns.
- AFrameWidth
- Width of each frame.
- AFrameHeight
- Height of each frame.
- ATimeLoop
- Should animation be repeated?, default
True .
- APlay
- Is animation playing? if not then current frame will be displayed.
|
 |
constructor CreateFrameSize(const URL: string; const AFrames, AColumns, AFrameWidth, AFrameHeight: Cardinal; const ASmoothScaling: Boolean = True; const ATimeLoop: Boolean = True; const APlay: Boolean = False); overload; |
Constructor that takes explicit frame size.
Parameters
- URL
- URL of source image.
- AFrames
- Total numer of animation frames.
- AColumns
- Number of columns.
- AFrameWidth
- Width of each frame.
- AFrameHeight
- Height of each frame.
- ASmoothscaling
- Enables interpolation, see TGLImageCore.SmoothScaling for details, default
True .
- ATimeLoop
- Should animation be repeated?, default True.
- APlay
- Is animation playing? if not then current frame will be displayed.
|
 |
destructor Destroy; override; |
|
 |
procedure Update(const SecondsPassed: TFloatTime); |
Update current frame.
Parameters
- SecondsPassed
- Time from previous update.
|
 |
procedure Play; |
Play playing animation., When playing, the Time will move forward when you call Update.
|
 |
procedure Stop; |
Stop playing animation. When stopped, the Time will not move forward, regardless if you call Update.
|
 |
procedure Pause; deprecated 'use Stop'; |
Warning: this symbol is deprecated: use Stop |
 |
procedure Draw; overload; |
Draw the sprite.
The overloaded version without AX, AY or ScreenRectangle parameters uses the last position set by Move method. This is the position of the bottom-left frame corner on screen.
The overloaded version without DrawWidth, DrawHeight or ScreenRectangle parameters uses the last size set by DrawingWidth, DrawingHeight properties. This is the size of the frame on screen.
All versions use the rotation set by the last Move method. This is the rotation of the frame on screen.
The overloaded versions deliberately look and work similar to TGLImageCore.Draw versions.
|
 |
procedure Draw(const AX, AY: Single); overload; |
|
 |
procedure Draw(const AX, AY, DrawWidth, DrawHeight: Single); overload; |
|
 |
procedure Draw(const ScreenRectangle: TRectangle); overload; |
|
 |
procedure DrawFlipped(const ScreenRect: TRectangle; const FlipHorizontal, FlipVertical: boolean); overload; |
Draw the sprite, optionally flipped horizontally and/or vertically. These methods ignore the HorizontalFlip, VerticalFlip, and DiagonalFlip – which axis is flipped (if any) depends only on the parameters to these methods.
|
 |
procedure DrawFlipped(const ScreenRect: TFloatRectangle; const FlipHorizontal, FlipVertical: boolean); overload; |
|
 |
procedure Move(AX, AY: Integer; ARot: Single=0); |
Move sprite to position and rotation.
|
 |
function AddAnimation(const AAnimation: TSpriteAnimation): Integer; overload; |
Add a custom animation (using an explicit sequence of frames), that can be later used by SwitchToAnimation.
Parameters
- AAnimation
- The animation information. The animation instance (TSpriteAnimation) becomes owned by this object, so don't free it yourself.
- AnimationFrames
- The animation information can also be given as a simple list of frame indexes. In this case, all frames are assumed to take the same time:
1 / FramesPerSecond .
Returns
The animation index, that can be used with SwitchToAnimation. |
 |
function AddAnimation(const AnimationFrames: array of Cardinal): Integer; overload; |
|
 |
function AddSpriteAnimation(const AnimationFrames: array of TSpriteAnimationFrame): Integer; deprecated 'use AddAnimation'; |
Warning: this symbol is deprecated: use AddAnimation |
 |
function SwitchToAnimation(const AAnimIndex: Integer; const ACustomFrame: Cardinal = 0): Boolean; |
Switch to the animation with index AAnimIndex. Use animation index obtained from AddAnimation to use a custom animation, or use -1 to use the default animation (spanning all sprite frames).
Returns
True on success, False if AAnimIndex is out of bounds.
|
 |
function Duration: TFloatTime; |
Duration, in seconds, of the currently used animation. See CurrentAnimation to know what the current animation is.
|
Properties
 |
property X: Integer read FX write FX; |
|
 |
property Y: Integer read FY write FY; |
|
 |
property CenterX: Single read GetCenterX write SetCenterX default 0.5; |
Center X of rotation. Values between 0 and 1.
|
 |
property CenterY: Single read GetCenterY write SetCenterY default 0.5; |
Center Y of rotation. Values between 0 and 1.
|
 |
property DrawingWidth: Cardinal read FDrawingWidth write FDrawingWidth; |
Destination frame width to draw.
|
 |
property DrawingHeight: Cardinal read FDrawingHeight write FDrawingHeight; |
Destination frame height to draw.
|
 |
property Center: TVector2 read GetCenter write SetCenter; |
Center of rotation. Values between 0 and 1.
|
 |
property Rotation: Single read GetRotation write SetRotation default 0; |
Rotation in degrees.
|
 |
property Frames: Cardinal read FFrames; |
Total number of frames. Readonly. Defined at creation.
|
 |
property FramesPerSecond: Single
read FFramesPerSecond write SetFramesPerSecond
default DefaultFramesPerSecond; |
How many frames per second to play. This is used only for the default sprite animation (spanning all frames). For the custom animations (added by AddAnimation), each frame has an explicit (possibly different) duration.
|
 |
property Frame: Cardinal read FFrame write SetFrame; |
Current frame.
|
 |
property Playing: Boolean read FPlaying write FPlaying default False; |
Does the animation proceeds forward when you call Update method.
|
 |
property TimeLoop: Boolean read FTimeLoop write FTimeLoop; |
Does the animation loop, that is display the same animation over and over when time exceeded the animation duration.
|
 |
property Time: TFloatTime read FTime write SetTime; |
Current time within the animation, it determines the current frame. Yoy can set this explicity. Alternatively, you can call the Update method continously while the animation is Playing, and then the time will increase automatically.
|
 |
property FrameWidth: Cardinal read FFrameWidth write FFrameWidth; |
Width of a single frame. Initial value is set by the constructor.
|
 |
property FrameHeight: Cardinal read FFrameHeight write FFrameHeight; |
Height of a single frame. Initial value is set by the constructor.
|
 |
property LeftMargin: Cardinal read FLeftMargin write FLeftMargin default 0; |
X margin for frame position on the underlying image. Useful if the first frame doesn't start at X=0.
|
 |
property LeftMarginOffset: Cardinal read FLeftMargin write FLeftMargin default 0; deprecated 'use LeftMargin'; |
Warning: this symbol is deprecated: use LeftMargin |
 |
property TopMargin: Cardinal read FTopMargin write FTopMargin default 0; |
Y margin for frame position on the underlying image. Useful if the first frame doesn't start at Y=0.
|
 |
property TopMarginOffset: Cardinal read FTopMargin write FTopMargin default 0; deprecated 'use TopMargin'; |
Warning: this symbol is deprecated: use TopMargin |
 |
property HorizontalSpacing: Cardinal
read FHorizontalSpacing write FHorizontalSpacing default 0; |
Horizontal spacing between frames. Use this if you have an empty space at the right of every frame in your spritesheet. This is useful to avoid frames "bleeding" into each other (due to smooth scaling).
|
 |
property VerticalSpacing: Cardinal
read FVerticalSpacing write FVerticalSpacing default 0; |
Vertical spacing between frames. Use this if you have an empty space at the top (or bottom, if VerticalSpacingBottom) of every frame in your spritesheet. This is useful to avoid frames "bleeding" into each other (due to smooth scaling).
|
 |
property VerticalSpacingBottom: boolean
read FVerticalSpacingBottom write FVerticalSpacingBottom default false; |
When True , the VerticalSpacing is assumed to be at the bottom of every frame, not top.
|
 |
property TimeBackwards: Boolean read FTimeBackwards write FTimeBackwards default False; |
Should we play the animation backwards after playing it forward. See TVideo.TimeBackwards.
|
 |
property CurrentAnimation: Integer read FCurrentAnimation default -1; |
Currently used animation. Equal to -1 when we're using the default animation spanning all sprite frames. Otherwise, indicates a custom animation index (added by AddAnimation and used by SwitchToAnimation).
Call SwitchToAnimation to change this.
|
 |
property HorizontalFlip: Boolean read FHorizontalFlip write FHorizontalFlip default False; |
Is sprite horizontal flipped?
|
 |
property VerticalFlip: Boolean read FVerticalFlip write FVerticalFlip default False; |
Is sprite vertical flipped?
|
 |
property DiagonalFlip: Boolean read FDiagonalFlip write FDiagonalFlip default False; |
Is sprite diagonal flipped?
|
Generated by PasDoc 0.15.0.
|