pesde goatsoft / lucy

Image

A picture: a dance icon, a song cover, a shop item. Give it an asset id or any content url.

Image exampleImage example
Lucy.Stack.new({
    direction = "horizontal",
    gap = "Space3",
    align = "center",
    children = {
        Lucy.Image.new({
            image = "rbxthumb://type=AvatarHeadShot&id=1&w=150&h=150",
            size = UDim2.fromOffset(64, 64),
            rounded = "lg",
        }),
        Lucy.Stack.new({
            gap = "Space1",
            size = UDim2.fromOffset(240, 0),
            automaticSize = Enum.AutomaticSize.Y,
            children = {
                Lucy.Text.new({ text = "DJ Lucy", variant = "large" }),
                Lucy.Text.new({ text = "Resident DJ, live in the Booth", variant = "muted" }),
            },
        }),
    },
    Parent = parent,
})

For icons that should follow the theme's colours, use Icon.

Props

PropTypeDefaultState keyWhat it does
imagenumber or string""yesAn asset id, or a url such as rbxassetid://... or rbxthumb://...
fitstring"contain"yesHow the picture fills its box: contain, cover, fill or tile
visiblebooleantrueyesShows or hides it
sizeUDim264 by 64Its size
aspectRationumberKeeps width over height, whatever its size
roundedstringnoneRounded corners: none, sm, md, lg, xl or full
placeholderbooleantrueA pulsing box in its place until the picture loads; false leaves it out

It also takes the props every component takes.

What each fit does:

FitThe picture
containFits inside the box whole, leaving space at the sides or ends
coverFills the box and is cut off at the sides or ends
fillStretches to the box
tileRepeats across the box

Lucy.Image.url(value) turns an asset id into a url, and leaves urls as they are. An id of 0 gives an empty image.

Loading

While a picture loads, a placeholder pulses in its place in the theme's $Muted and fades away once the picture is there, so a slow picture looks deliberate rather than missing. A picture fetched already with Lucy.preload shows at once, with no placeholder.

Preloading

Lucy.preload(ids, options?) fetches pictures before they are shown: call it while a loading screen is up, or when a shop is about to open. Every call shares one queue: a picture fetched before, or waiting already, is not fetched again, and the queue works a few at a time so a long list never holds up the game.

On a client, each picture is drawn once, tiny and nearly see-through, in a ScreenGui under everything else, until it has loaded. Downloading a picture is not enough: the first time it is drawn still takes up to a second or so, and that is the grey box a player sees. A picture drawn once this way shows at once from then on.

local job = Lucy.preload(shopIcons)
progressBar(job.progress)        -- 0 to 1, a getter
if job.done() then ... end

Lucy.preload(featured, { first = true })   -- ahead of what is waiting

Ids are asset ids, urls or instances. Lucy.Preload.isLoaded(id) says whether a picture has been fetched. A virtual Grid takes a preload function and fetches every item's pictures for you.

A picture warmed this way counts as loaded for Lucy.Preload.fresh seconds (120). Roblox may drop a picture nothing shows, so after that, asking for it again draws it again: warm close to when a picture is needed.

Pinned pictures

Roblox can unload a picture again once nothing on the screen uses it, so a picture preloaded at the start may be gone by the time its panel opens. Pin what must always be ready, once, at launch: what the first screens show and what every player opens.

local hud = Lucy.preload(hudPictures, { pin = true })
hud.release()   -- later, if it is no longer needed: Roblox may unload it again

A pinned picture keeps its tiny copy drawn for as long as it is pinned. A picture pinned by two calls stays until both release it. Pin with care: each pinned picture stays in memory for as long as the game runs, so pin what is always needed and preload the rest just before it is. Icon sheets are pinned for you.

Lucy.Preload.isPinned(id) says whether a picture is pinned, and Lucy.Preload.stats() counts what is pinned, warmed (fetched through the queue) and waiting.

Examples

A track cover that fills its card, cut to fit:

Lucy.Image.new({
    image = track.coverId,
    fit = "cover",
    size = UDim2.fromScale(1, 1),
    rounded = "md",
    Parent = card,
})

A coin pack's own picture from Roblox:

Lucy.Image.new({
    image = `rbxthumb://type=DeveloperProduct&id={coinPackId}&w=150&h=150`,
    size = UDim2.fromOffset(72, 72),
    Parent = shopRow,
})

For a player's headshot, use Avatar.

Preview

In Studio, from the command bar: Lucy.Preview.show("Image").