menu_bookDocumentation
s&box SpriteRenderer: Billboard Modes, Animation Control, Broadcast Events, and Rendering Options
s&box SpriteRenderer: Animated Sprites, Billboard Modes, and Broadcast Events
SpriteRenderer renders a Sprite asset in the s&box world with support for animation, billboarding, and frame events.Basic Usage
CSHARP
var sr = AddComponent<SpriteRenderer>();
sr.Sprite = ResourceLibrary.Get<Sprite>( "sprites/explosion.sprite" );
sr.Size = new Vector2( 64, 64 );
sr.Color = Color.White;
sr.Billboard = SpriteRenderer.BillboardMode.Always;Billboard Modes
CSHARP
SpriteRenderer.BillboardMode.Always // always face camera (default)
SpriteRenderer.BillboardMode.YOnly // rotate around Y axis only
SpriteRenderer.BillboardMode.Particle // particle-style billboard
SpriteRenderer.BillboardMode.None // no billboarding (use object rotation)Animation Control
CSHARP
// Play by name
sr.PlayAnimation( "run" );
// Control playback
sr.PlaybackSpeed = 1.0f; // 0 = paused, negative = reverse
sr.CurrentFrameIndex = 3; // jump to frame 3
// Read state
bool isAnimated = sr.IsAnimated;
string animName = sr.CurrentAnimation?.Name;
Texture frame = sr.Texture; // current frame textureAnimation Callbacks
CSHARP
sr.OnAnimationStart = ( name ) => Log.Info( $"Started: {name}" );
sr.OnAnimationEnd = ( name ) => Log.Info( $"Ended: {name}" );
sr.OnBroadcastMessage = ( msg ) => HandleEvent( msg );Broadcast Events (Frame Events)
Sprite frames can have broadcast events defined in the s&box sprite editor:
- CustomMessage — fires OnBroadcastMessage with a string
- PlaySound — automatically plays a sound at the sprite's position
- SpawnPrefab — spawns a prefab at the sprite's position (game mode only, not in editor)
Rendering Options
CSHARP
sr.Additive = false; // additive blending
sr.Opaque = false; // opaque rendering (dithers semi-transparent pixels)
sr.AlphaCutoff = 0.5f; // alpha cutoff for opaque mode
sr.Lighting = false; // lit by scene lighting
sr.DepthFeather = 0f; // soft intersection with geometry
sr.FogStrength = 1.0f; // fog blending
sr.TextureFilter = FilterMode.Bilinear; // use Point for pixel art
Was this helpful?