Menu

Recreating Minecraft's XP bar with three SVGs and one @keyframes rule
📰

Recreating Minecraft's XP bar with three SVGs and one @keyframes rule

DEV Community: laravel·Hugo Bachmann·about 11 hours ago
#ogNosTcz
#devtolaravel#devto#dev#game#server
Long article (1852 words) — no AI summary yet.
Reading 0:00
15s threshold

On the Agoralis player dashboard, the job progress box shows a green XP bar that shimmers exactly like the one above the hotbar in Minecraft. Players recognise it instantly, and it shows their real job XP, pulled from the game server.

There is no canvas, no JavaScript and no GIF behind it. It is three small SVGs drawn pixel by pixel, one @keyframes rule that swaps two of them, and a Blade loop that decides how many segments to draw. This article shows the production code, why we picked this approach, and the edge cases we know it has.

TL;DR

Draw the bar as pixel-art SVGs: one tile for the empty track, two frames for a filled segment. Our second frame is the first one rotated 180°.

Tile the empty track with background-repeat: repeat-x and stack filled segments as 20 × 8 px flex children on top of it.

Alternate the two frames with a @keyframes rule on the background.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.