base:gif_to_sprites
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:gif_to_sprites [2021-12-20 21:24] (current) – created mace | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== GIF to sprites ====== | ||
+ | By Mace | ||
+ | |||
+ | This is a Kick Assembler script that turns a GIF into separate sprites. The order is represented by strings that contain letters, enabling you to make a sprite font with only the letters that you use, but distributed into memory where the sprite pointers have screen code offset. | ||
+ | |||
+ | To clearify: if you have the A as your first letter in the top left of your GIF, it will be transfered to spriteMemory + 1*64 (where 1 is the screencode of the letter A). So if spriteMemory is $4000, the 64x21 top left pixels will be transfered to $4040. | ||
+ | |||
+ | The GIF could look something like the one below. The script assumes black letters on a white background. Compare the content of the GIF with the strings in lines 13 and 14 of the script and you'll see the resemblance. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <code [enable_line_numbers=" | ||
+ | .label spriteMemory = $4000 | ||
+ | |||
+ | * = spriteMemory // spriteMemory is where you want your sprites | ||
+ | |||
+ | // Load the GIF with the sprite font, each letter in a 64x21 grid | ||
+ | .var spriteFont = LoadPicture(" | ||
+ | |||
+ | // Create a List() that contains the letters in your font | ||
+ | // in the order as they appear in the GIF | ||
+ | .var fontMap = List() | ||
+ | |||
+ | // Add strings that contains all the letters for each line in the GIF | ||
+ | .eval fontMap.add(" | ||
+ | .eval fontMap.add(@" | ||
+ | // (@ indicates escape code) | ||
+ | |||
+ | // Parse the strings (var l = lines) in the fontMap List() | ||
+ | .for (var l=0; l< | ||
+ | |||
+ | // Parse each string (var p = position) | ||
+ | .for (var p=0; p< | ||
+ | |||
+ | // The location in memory is determined by the value of the letter | ||
+ | * = spriteMemory + fontMap.get(l).charAt(p)*64 // determine memory location | ||
+ | |||
+ | // Transfer the graphics in the GIF to the sprite | ||
+ | .fill 63, spriteFont.getSinglecolorByte((p*3)+mod(i, | ||
+ | |||
+ | } // for-loop p | ||
+ | } // for-loop l | ||
+ | </ |
base/gif_to_sprites.txt · Last modified: 2021-12-20 21:24 by mace