Namespaced asset API + spritesheet/atlas with named cells #81
Labels
No labels
area:ci
area:docs
area:input
area:net
area:rendering
area:repo
area:stdlib
area:tooling
area:types
cleanup
dx
priority:high
priority:low
priority:medium
proposal
status:in-progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: workshopsoft/ludic#81
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sprite loading is a bare
png_load("assets/sprites/floor0.png")— unnamespaced, and one file per 16x16 sprite. There is no general (non-Tiled) spritesheet/atlas API: you cannot load one sheet and address a cell by grid coords or by name.Proposal: a namespaced API, e.g.
Sprite.sheet(path, cellw, cellh)-> handle,Sprite.cell(sheet, col, row)/Sprite.define(name, sheet, col, row)-> id, plusAssets.*for load/lookup. Loading many individual PNGs is slower and clutters the project.Seen in an external game that had to pre-slice the 0x72 atlas into individual PNG files.
Please beware that some sprites may or may not cover more than 1 cell.
Shipped in
f3f1336(full suite 114/0, goldens byte-identical, fixpoint intact).A namespaced spritesheet / atlas API over the variable-size image loader, so a cell is a sub-rect of the kept image — sprites are no longer restricted to the 16x16 sprite table:
Sprite.sheet(path, cellw, cellh) -> handle— load one sheet, remember its cell gridSprite.cell(sheet, col, row) -> id— a cell by grid coordsSprite.cell_span(sheet, col, row, cols, rows) -> id— a sprite spanning more than one cell (per your note that some sprites cover >1 cell — a tall character, a wide object)Sprite.define(name, sheet, col, row)/Sprite.named(name)— name a cell and look it up (content data can drive rendering with no hard-coded ids)Sprite.draw(id, x, y)/Sprite.draw_scaled(id, x, y, scale)— blit through the camera / zoom / clip, exactly likeScreen.spriteSprite.width(id)/Sprite.height(id)Assets.image(path) -> id(whole file as one sprite) /Assets.load(alias) /Assets.get(name)(alias ofSprite.named)Spliced on demand, so a program that uses neither
Sprite.sheetnorAssets.*is byte-identical. Verified byexamples/library/atlas.ludicagainst a real 12x11 Kenney sheet (tilemap_packed.png): single cell (16x16), a 2x3 multi-cell span (32x48), named define/lookup, Assets.image, and a pixel-readback that the sprite drew — prints16 16 32 48 1 1 1 16 1. 14 docs pages added.Note: this atlas id-space is distinct from the
Spriteengine component (#85), which draws png_load ids via the 16x16 table; wiring atlas ids into that component's auto-draw is a natural follow-up.