gdmp.sprites
Esta página aún no está disponible en tu idioma.
Runs on: client. Since API level 103.
Your package’s own pictures, drawn natively by Geometry Dash’s engine (cocos2d-x sprites, the way GD draws its own
art) inside the running level: characters with frame animations, scenery, parallax backgrounds, effects. Play clients
with the nativeUI capability. Nothing is drawn in a web page: the sprites are part of the level, scroll with it, sort
with GD’s own layers, and cost the game what its own sprites cost.
| Call | What it does |
|---|---|
load(path, {frameWidth, frameHeight, pixel, smooth}) → sheet |
a PNG of the package ("art/rider.png", ≤ 4096 × 4096) cut into equal frames, row by row (no size = the whole picture is one frame). pixel = level units per picture pixel (1; a GD block is 30 units, so with pixel: 2 a 15-pixel-tall character is one block high). Pixels stay sharp (nearest) unless smooth: true. Returns {id, frames, columns, rows, width, height, path}; loading the same cut twice gives the same sheet. 64 sheets |
create({sheet, frame, x, y, z, parallax, parallaxY, scale, flipX, flipY, color, opacity, visible, anchor, tint, follow, faceWithPlayer, hidePlayerIcon, play}) → sprite |
see below. 1024 sprites; a bad value throws TypeError with the reason |
sprite .set({...the same fields...}) → bool |
only the fields given change (x and y together) |
sprite .play({frames, fps, loop}) → bool |
frames: [0, 1, 2, 1] or {from: 0, to: 7} (32 at most), fps 0..60 (8), loop (true; false = stops on the last frame). Runs in the engine every frame |
sprite .stop() |
the animation stops on the frame it shows |
sprite .moveTo(x, y, ms) → bool |
glides there in ms (from where it is drawn now), in the engine every frame; set({x, y}) jumps |
sprite .remove() → bool |
|
camera() → {left, bottom, width, height} | null |
the screen, in level units (null before the level is drawn) |
setTint(color) |
every sprite with tint: true (the default) is multiplied by this colour: day "#ffffff", dusk "#c08070", night "#3a4a7a". One call recolours the whole scene |
Sprite fields: x, y level units (where the anchor sits; anchor: [0.5, 0] = bottom centre, the default is the
centre [0.5, 0.5]); z the draw order among the sprites and the level’s own layers (negative = behind the player);
parallax 1 = moves with the level, 0 = fixed on the screen (a sky), 0.3 = far away (hills), above 1 = closer than
the level; parallaxY the same for up / down (defaults to parallax; far scenery in a level whose camera rides high wants
parallaxY: 1, or it drifts by the camera’s height); scale (1), flipX / flipY, color "#RRGGBB" (multiplies the picture), opacity 0..1, visible.
A player’s icon as a sprite – create({icon: "local" | playerId, x, y, z, scale, follow, faceWithPlayer}): not a
picture but that player’s real icon (their cube in their colours and glow – their GDMP icon when they chose one),
built natively like the remote players’ icons and rebuilt when their look changes. It moves, scales, flips, hides and
sorts like any sprite; color multiplies its own colours (and the scene tint applies unless tint: false), opacity
fades it – frames do not apply. Lantern Vale puts it on the rider’s shoulders, and a second one upside down
(flipY: true, opacity: 0.45, color: "#8aaccc") in the water below as its reflection. A
follower’s sideways offset turns with the player (faceWithPlayer): a head or a held item stays in front.
Following a player – follow: "local" or a player id: the sprite sits on that player every frame (x / y become an
offset), faceWithPlayer (true) flips it with the player’s facing, and hidePlayerIcon: true stops drawing that
player’s GD icon while the sprite lives – your own character instead of the GD icon, moved by GD’s own platformer
physics, with GDMP’s interpolation for the other players.
const rider = gdmp.sprites.load("art/rider.png", { frameWidth: 48, frameHeight: 40, pixel: 1.5 });const me = gdmp.sprites.create({ sheet: rider, anchor: [0.5, 0], y: -15, follow: "local", hidePlayerIcon: true, z: 5, play: { frames: { from: 0, to: 3 }, fps: 6 } }); // idlegdmp.input.onButton(e => { // walk while a key is down if (e.button === "left" || e.button === "right") me.play(e.down ? { frames: { from: 4, to: 11 }, fps: 12 } : { frames: { from: 0, to: 3 }, fps: 6 });});const sky = gdmp.sprites.load("art/sky.png", { smooth: true });gdmp.time.after(500, () => { // once the level is drawn const cam = gdmp.sprites.camera(); gdmp.sprites.create({ sheet: sky, x: cam.width / 2, y: cam.height / 2, parallax: 0, z: -1000, scale: cam.width / sky.width });});How it works: the picture becomes a texture in GD’s own texture cache (CCTextureCache::addImage, sharp with
setAliasTexParameters); each sprite is a CCSprite cut from it (createWithTexture, setTextureRect per frame) under
the level’s object layer, the parent of GD’s player. The script’s calls go into a bounded queue; the game thread applies
them and runs animations, glides, follows and parallax every frame (the camera is the object layer’s own transform).
A level restart or change rebuilds every sprite where it was. Limits: 64 sheets, 1024 sprites, 32 frames per animation,
4096 queued changes (more at once: the call returns false / throws “busy”).
TypeScript
Section titled “TypeScript”The declarations from the GDMP types (namespace GDMP), comments included:
interface Sheet { readonly id: number; readonly frames: number; readonly columns: number; readonly rows: number; readonly width: number; readonly height: number; readonly path: string }
interface Animation { frames: number[] | { from: number; to: number }; fps?: number; loop?: boolean }
interface SpriteFields { x?: number; y?: number; /** Draw order among the sprites and the level's layers (negative = behind the player). */ z?: number; frame?: number; /** 1 = moves with the level, 0 = fixed on the screen, 0.3 = far away. */ parallax?: number; parallaxY?: number; scale?: number; flipX?: boolean; flipY?: boolean; color?: Color; /** 0..1. */ opacity?: number; visible?: boolean; /** [0.5, 0] = bottom centre; default the centre [0.5, 0.5]. */ anchor?: [number, number]; /** Multiplied by `setTint` (default true). */ tint?: boolean; /** Sit on that player every frame (x / y become an offset). */ follow?: 'local' | PlayerId; faceWithPlayer?: boolean; hidePlayerIcon?: boolean;}
type SpriteCreate = SpriteFields & ({ sheet: Sheet | number; play?: Animation } | { icon: 'local' | PlayerId });
interface Sprite { set(fields: SpriteFields): boolean; play(animation: Animation): boolean; stop(): void; moveTo(x: number, y: number, ms: number): boolean; remove(): boolean;}
interface Sprites { load(path: string, options?: { frameWidth?: number; frameHeight?: number; pixel?: number; smooth?: boolean }): Sheet; create(sprite: SpriteCreate): Sprite; camera(): { readonly left: number; readonly bottom: number; readonly width: number; readonly height: number } | null; setTint(color: Color): void;}