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.
Returns a reference to the sprite asset being used. Remember, a “Sprite” is actually a Font
local sprite = self.gameObject.spriteRenderer:GetSprite()
Sets the SpriteRenderer’s sprite to the given “Sprite” (Font) asset
sprite
- CS Asset
(required) the Font asset for the desired sprite
self.gameObject.spriteRenderer:SetSprite(CS.FindAsset("Sprites/Sample/SampleSprite", "Font"))
Returns the current animation of the SpriteRenderer
local currentAnimation = self.gameObject.spriteRenderer:GetAnimation()
Sets the animation of the SpriteRenderer to the given spritesheet Font asset
animationAsset
- CS Asset
(required) the spritesheet to assignnumFrames
- number
(required) the number of frames in the animation
self.gameObject.spriteRenderer:SetAnimation(CS.FindAsset("Sprites/Sample/Animations/Idle", "Font"))
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.
ticks
- number
(required) the number of game ticks per frame of the animation
self.gameObject.spriteRenderer:SetAnimationFrameDuration(30)
Gets the duration of the current animation in seconds
local animationLength = self.gameObject.spriteRenderer:GetAnimationDuration()
Starts playback of the current animation
loop
- bool
(optional) whether or not to loop the animation. Default: true
self.gameObject.spriteRenderer:StartAnimationPlayback(true)
Stops playback of current animation
self.gameObject.spriteRenderer:StopAnimationPlayback()
Returns whether or not an animation is currently playing
local isAnimationPlaying = self.gameObject.spriteRenderer:IsAnimationPlaying()
Returns the current opacity of the SpriteRenderer
local spriteOpacity = self.gameObject.spriteRenderer:GetOpacity()
Sets the opacity of the SpriteRenderer to the given value, clamping between 0 and 1
opacity
- number
(required) a number between 0 and 1 to apply to the opacity
self.gameObject.spriteRenderer:SetOpacity(.5)