
Random Flipbook Frame
You need to own this item to leave a rating.
Example video how used..
https://youtu.be/4ODZ9AvCVM4
Comprehensive one piece of script
for multiple ideas in your creations.
Supports up to 256 frames/images/sprites..
Just copy/paste script into your own creations
and make adjustments to your specs then resell
if you wish..
# Random Spritesheet Frame Clicker - Script Overview
## Brief Description
A Sansar script that randomly changes the displayed frame of a spritesheet material each time a user clicks on the object. Perfect for creating interactive elements like dice, card decks, slot machines, or any object that needs to randomly display different images from a sprite grid.
## What It Does
When attached to a mesh object with a spritesheet material (e.g., a 4x4 grid with 16 frames), this script makes the object interactive. Each time someone clicks on it, the script randomly selects a different frame from the spritesheet, creating a visual change. Think of it like shuffling through different images or patterns with each click.
## Key Features
- **Random Frame Selection**: Automatically picks a random frame from your spritesheet
- **Smart Selection**: Ensures each click shows a different frame than the current one
- **Permission Controls**:
- Owner-only mode for private objects
- Allowed avatars list for controlled access
- Public mode (default) for everyone to use
- **Optional Sound Effects**: Add a click sound for audio feedback
- **Smooth or Instant Transitions**: Choose between instant frame changes or smooth animated transitions
- **Configurable**: Adjust total frames, starting frame, transition speed, and more
## How It Works
1. User clicks on the object with the script attached
2. Script checks if the user has permission (owner-only or allowed list)
3. Script generates a random frame number (different from the current frame)
4. Material properties are updated using Sansar's FlipbookFrame API
5. Optional click sound plays
6. The new frame is displayed on the object
## Setup Requirements
1. **Mesh Object**: An object with a mesh component
2. **Spritesheet Material**: A material with a flipbook texture (e.g., 4x4 grid = 16 frames)
3. **Scriptable Property**: The mesh must be set to "Scriptable" in its properties
4. **Script Attachment**: This script attached to the mesh object
## Configuration Options
- **Interaction Prompt**: The hover text users see (e.g., "Click to roll dice")
- **Total Frames**: Number of frames in your spritesheet (16 for a 4x4 grid)
- **Starting Frame**: Which frame shows when the scene loads (0-15)
- **Material Name**: Specify which material to control (or leave empty for first material)
- **Transition Time**: Duration of frame change animation (0 = instant)
- **Interpolation Mode**: Animation style (step, linear, smoothstep, easein, easeout)
- **Owner Only**: Restrict to scene owner only
- **Allowed Avatars**: Comma-separated list of avatar names who can interact
- **Click Sound**: Optional sound effect resource
- **Sound Loudness**: Volume level (0-100)
## Common Use Cases
- **Dice**: Random dice face on each roll
- **Slot Machines**: Random symbols for casino games
- **Card Decks**: Draw random cards from a deck
- **Character Expressions**: Randomly change facial expressions
- **Pattern Generator**: Display random patterns or designs
- **Mystery Box**: Show different items randomly
- **Collectibles**: Random item displays for treasure hunts
- **Quiz Games**: Display random questions or images
## Technical Details
- Uses Sansar's `MaterialProperties.FlipbookFrame` API
- Implements C# `Random` class for frame generation
- Validates mesh scriptability and material availability
- Includes error handling and debug logging
- Supports multiple interpolation modes for smooth transitions
## Example Scenario
You have a die object with a 4x4 spritesheet showing dice faces (16 frames). When players click the die, it randomly switches to show a different face, simulating a dice roll. You can set it to "instant" transition for a snap change, or use a smooth transition to animate between faces.