development:csdk:1.0:sprites
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
development:csdk:1.0:sprites [2024/11/08 01:57] – removed - external edit (Unknown date) 127.0.0.1 | development:csdk:1.0:sprites [2024/11/08 01:57] (current) – ↷ Page moved from development:csdk:sprites to development:csdk:1.0:sprites clyde | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Importing and Drawing Sprites ====== | ||
+ | |||
+ | The SDK makes it easy to bring images into your game after you've [[development: | ||
+ | |||
+ | **Warning**: | ||
+ | =====Import===== | ||
+ | |||
+ | The 2MB Cartridges have 128 banks of 16KB each, and the SDK scripts are designed to assign image assets to these banks based on the contents of the //assets// folder. Each subfolder of //assets// comprises one of the cartridge banks. Files dropped directly into the //assets// folder are ignored by the import scripts. | ||
+ | |||
+ | After adding files to folders inside //assets//, run <code bash> | ||
+ | |||
+ | For example, in the games/tanks branch of the SDK there are three assets folders: " | ||
+ | <code bash> | ||
+ | [ ' | ||
+ | [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ] | ||
+ | [ ' | ||
+ | </ | ||
+ | |||
+ | In addition these files will be created in src/ | ||
+ | |||
+ | * font.h | ||
+ | * gfx.h | ||
+ | * music.h | ||
+ | |||
+ | =====Drawing===== | ||
+ | |||
+ | Drawing sprites on the GameTank is a two-step process. Before a sprite can be drawn it must be loaded into Sprite RAM. Once it is loaded into one of the sprite banks, it can be drawn either by specifying a rectangular portion of a sprite bank, or by an index into frame data exported by Aseprite. | ||
+ | |||
+ | The function // | ||
+ | |||
+ | The generated header files, eg. src/gen/gfx if you created a " | ||
+ | |||
+ | <code c> | ||
+ | //Near top of file | ||
+ | #include " | ||
+ | ... | ||
+ | //During your init process | ||
+ | load_spritesheet(& | ||
+ | load_spritesheet(& | ||
+ | </ | ||
+ | |||
+ | =====Drawing by rectangle===== | ||
+ | |||
+ | Once your graphics are loaded into a sprite bank, you can draw them with // | ||
+ | |||
+ | <code c> | ||
+ | draw_sprite(X, | ||
+ | </ | ||
+ | |||
+ | X and Y indicate coordinates on the screen. W and H are the width and height. GX and GY are the coordinates in the source image which you'd use to pick a tile or frame of animation from a sheet. RAMBANK is the bank number that you earlier specified to load_spritesheet. | ||
+ | |||
+ | // | ||
+ | |||
+ | When there' | ||
+ | |||
+ | =====Drawing by frame number===== | ||
+ | |||
+ | If you've exported a packed sprite sheet alongside JSON frame data, you can use // | ||
+ | |||
+ | <code c> | ||
+ | void draw_sprite_frame( | ||
+ | const Frame *sprite_table, | ||
+ | char sprite_table_bank, | ||
+ | char x, char y, | ||
+ | char frame, | ||
+ | char flip, | ||
+ | char bank); | ||
+ | </ | ||
+ | |||
+ | Referring to the JSON data is similar to referring to the sprite data in // | ||
+ | |||
+ | <code c> | ||
+ | draw_sprite_frame(& | ||
+ | </ | ||
+ | |||