Last active
September 10, 2017 20:20
-
-
Save kdrnic/c8a5f5dd38f06edfa57bb6cf3a790ca3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Problem: Defining an API for sprite drawing calls | |
| Some parameters of sprites: | |
| - The bitmap with the sprite sheet | |
| - Width and height | |
| - Position X, Y | |
| - Scale | |
| - Rotation angle | |
| - Flips (vertical, horizontal) | |
| A batch version also to be available | |
| */ | |
| // Most basic way | |
| MaskedBlit(screen, bmp, frame * frame_w, 0, frame_w, frame_h, x, y); | |
| // Basic optimisation | |
| var b = new Int32Array(6); | |
| b[0] = frame_w; | |
| b[1] = frame_h; | |
| b[2] = frame * frame_w; | |
| b[3] = 0; | |
| b[4] = x; | |
| b[5] = y; | |
| BatchMaskedBlit(screen, bmp, b); | |
| // Fancier way #1 | |
| SetSpriteSheet(bmp, frame_w, frame_h); | |
| DrawSprite(screen, frame, x, y); | |
| // Fancier way #2 | |
| DrawSprite(screen, {bitmap: bmp, width: frame_w, height: frame_h, x: x, y: y}); | |
| // Basic optimisation | |
| var b = new Int32Array(4); | |
| b[0] = x; | |
| b[1] = y; | |
| b[3] = frame; | |
| BatchDrawSprite(screen, {bitmap: bmp, width: frame_w, height: frame_h}, b); | |
| // Fancier way #3 | |
| var s = CreateSpriteSheet(bmp, frame_w, frame_h); | |
| DrawSprite(screen, s, x, y, frame); | |
| // The above with the extra parameters, a varadic function: | |
| DrawTransformSprite(screen, s, SPRITE_ROTATE | SPRITE_SCALE | SPRITE_FLIP, x, y, frame, angle, scale, FLIP_V | FLIP_H); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment