sidescroller-framework

SpriteRenderer Component API

The SpriteRenderer object handles display and animation of sprites. In SFramework, sprites are represented in Fonts. Information on setting up a Font asset to act like a spritesheet can be found LINK_TODO.

Contents

SpriteRenderer

SpriteRenderer:GetSprite

Returns a reference to the sprite asset being used. Remember, a “Sprite” is actually a Font

Example

local sprite = self.gameObject.spriteRenderer:GetSprite()

SpriteRenderer:SetSprite

Sets the SpriteRenderer’s sprite to the given “Sprite” (Font) asset

Arguments

SpriteRenderer:GetAnimation

Returns the current animation of the SpriteRenderer

Example

local currentAnimation = self.gameObject.spriteRenderer:GetAnimation()

SpriteRenderer:SetAnimation

Sets the animation of the SpriteRenderer to the given spritesheet Font asset

Arguments

SpriteRenderer:SetAnimationFrameDuration

Sets the animation’s frame duration of the SpriteRenderer to the given number of game ticks. Keep in mind that there are 60 ticks per second in CraftStudio. So for instance, if you want to play an animation at 5 frames per second then you would divide 60 by 5 to get the number of ticks. The default frame duration is 5 ticks.

Arguments

SpriteRenderer:GetAnimationDuration

Gets the duration of the current animation in seconds

Example

local animationLength = self.gameObject.spriteRenderer:GetAnimationDuration()

SpriteRenderer:StartAnimationPlayback

Starts playback of the current animation

Arguments

SpriteRenderer:StopAnimationPlayback

Stops playback of current animation

Example

self.gameObject.spriteRenderer:StopAnimationPlayback()

SpriteRenderer:IsAnimationPlaying

Returns whether or not an animation is currently playing

Example

local isAnimationPlaying = self.gameObject.spriteRenderer:IsAnimationPlaying()

SpriteRenderer:GetOpacity

Returns the current opacity of the SpriteRenderer

Example

local spriteOpacity = self.gameObject.spriteRenderer:GetOpacity()

SpriteRenderer:SetOpacity

Sets the opacity of the SpriteRenderer to the given value, clamping between 0 and 1

Arguments