Class TSprite
Unit
Declaration
type TSprite = class(TObject)
Description
Warning: this symbol is deprecated.
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.
Instead of this, load sprite sheets to TCastleScene from .castle-sprite-sheet format.
Hierarchy
- TObject
- TSprite
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: TDrawableImage; 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: Single; 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 OwnsImage: Boolean read FOwnsImage write FOwnsImage default true; |
|
property X: Single read FX write FX; |
|
property Y: Single read FY write FY; |
|
property Position: TVector2 read GetPosition write SetPosition; |
|
property CenterX: Single read GetCenterX write SetCenterX default 0.5; deprecated 'use RotationCenter'; |
|
property CenterY: Single read GetCenterY write SetCenterY default 0.5; deprecated 'use RotationCenter'; |
|
property DrawingWidth: Single read FDrawingWidth write FDrawingWidth; |
|
property DrawingHeight: Single read FDrawingHeight write FDrawingHeight; |
|
property DrawRect: TFloatRectangle read GetDrawRect write SetDrawRect; |
|
property RotationCenter: TVector2 read GetRotationCenter write SetRotationCenter; |
|
property Center: TVector2 read GetRotationCenter write SetRotationCenter; deprecated 'use RotationCenter'; |
|
property Rotation: Single read GetRotation write SetRotation default 0; |
|
property Color: TCastleColor read GetColor write SetColor; |
|
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 SmoothScaling: boolean read FSmoothScaling write SetSmoothScaling; |
|
property SmoothScalingSafeBorder: Boolean
read FSmoothScalingSafeBorder write FSmoothScalingSafeBorder
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
|
constructor CreateFrameSize(const AImage: TDrawableImage; const AFrames, AColumns, AFrameWidth, AFrameHeight: Cardinal; const ATimeLoop: Boolean = True; const APlay: Boolean = False); overload; |
|
Constructor that takes explicit frame size, and loaded TDrawableImage instance.
Parameters
|
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
|
destructor Destroy; override; |
|
procedure Update(const SecondsPassed: TFloatTime); |
|
Update current frame. Parameters
|
procedure Play; |
|
Play playing animation., When playing, the Time will move forward when you call Update. |
procedure Stop; |
|
|
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 TDrawableImage.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 Draw(const ScreenRectangle: TFloatRectangle); 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 – 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: Single; 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
ReturnsThe 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
|
function Duration: TFloatTime; |
|
Duration, in seconds, of the currently used animation. See CurrentAnimation to know what the current animation is. |
Properties
property OwnsImage: Boolean read FOwnsImage write FOwnsImage default true; |
|
By default this class "owns" the underlying image, even when passed explicitly to CreateFrameSize as TDrawableImage instance. That is, the underlying TDrawableImage instance will be automatically freed when the sprite will be freed. You turn it off with this property. |
property X: Single read FX write FX; |
|
property Y: Single read FY write FY; |
|
property Position: TVector2 read GetPosition write SetPosition; |
|
property DrawingWidth: Single read FDrawingWidth write FDrawingWidth; |
|
Destination frame width to draw. |
property DrawingHeight: Single read FDrawingHeight write FDrawingHeight; |
|
Destination frame height to draw. |
property DrawRect: TFloatRectangle read GetDrawRect write SetDrawRect; |
|
Drawing rectangle. This is just a shortcut to get / set properties X, Y, DrawingWidth, DrawingHeight. |
property RotationCenter: TVector2 read GetRotationCenter write SetRotationCenter; |
|
Center of rotation. Expressed as a fraction within the drawn ScreenRectangle, (0,0) means bottom-left corner, (1,1) means top-right corner. Default (0.5,0.5). |
property Center: TVector2 read GetRotationCenter write SetRotationCenter; deprecated 'use RotationCenter'; |
|
Warning: this symbol is deprecated: use RotationCenter |
property Rotation: Single read GetRotation write SetRotation default 0; |
|
Rotation in degrees. |
property Color: TCastleColor read GetColor write SetColor; |
|
Color multiplier of the sprite, see TDrawableImage.Color |
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 continuously 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 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 |
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 SmoothScaling: boolean read FSmoothScaling write SetSmoothScaling; |
|
Use smooth "bilinear" filtering when this is scaled. |
property SmoothScalingSafeBorder: Boolean
read FSmoothScalingSafeBorder write FSmoothScalingSafeBorder
default false; |
|
Prevent the color outside of rendered frame from creeping in, by scaling image a bit to the inside. Because of bilinear filtering (used when SmoothScaling), the colors of neighboring pixels may be visible when you render the sprite frame, and the sprite is significantly scaled. The "neighboring pixels" may mean "pixels from the adjacent sprite frame", or sprite border (in case sprite frame is at the edge of the image), or spacing between sprite frames (if any). One way to workaround this is to add a 1-pixel or 2-pixel spacing between each sprite frames, and fill this spacing with the same color (including alpha) as the neighbor pixels. Another workaround is to use this property. This renders a slightly smaller sprite frame, such that bilinear filtering doesn't have a chance to introduce colors from outside of the desired sprite frame. This is done only when SmoothScaling, otherwise this property is ignored. The downside is that everything is slightly scaled, and doesn't look perfect if you look closely at each pixel. This property is ignored |
Generated by PasDoc 0.16.0.