C Library Commands and How to Use Them

From Learn @ Cemetech
Revision as of 23:12, 2 September 2016 by Unicorn (talk | contribs) (Created page with "=Introduction= ---- This guide will eventually list almost every C Library command in the SDK, and give a detailed explanation on how to use each one. ---- ==Graphics Commands...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction


This guide will eventually list almost every C Library command in the SDK, and give a detailed explanation on how to use each one.


Graphics Commands

Here you will find all of the Graphx library commands


gfx_AllocSprite and gfx_GetSprite


This command is useful to set room aside in the program for new sprites you will create with gfx_GetSprite and/or for sprites to need to decompress.

In the graphx.h file:

/**
 * Allocates room on the heap for sprite data of given size
 * Takes a pointer to the routine used for malloc as well
 * Returns NULL upon failure to allocate space, otherwise a pointer to the sprite structure
 * Note that if you use the system malloc routine, it must be used elsewhere in your program
 * otherwise it will not be linked correctly
 */
gfx_image_t *gfx_AllocSprite(uint8_t width, uint8_t height, void *malloc_routine);
  • width - The width of the sprite you want to decompress or create
  • height - The height of the sprite you want to decompress or create
  • malloc_routine - Not exactly sure what this does, just put malloc when writing the command

Ok, so now we're going to show you how to use it. Check this example code out, to be explained afterwards.

//Make this a global:
gfx_image_t spriteName
malloc(0);
spriteName = gfx_AllocSprite(30, 40, malloc);
gfx_GetSprite(spriteName, 20, 50);
  • gfx_image_t spriteName defines the sprite variable
  • malloc(0); sets that malloc value to 0
  • spriteName = gfx_AllocSprite(30, 40, malloc); sets spriteName to the width and height of the next few values
  • gfx_GetSprite(spriteName, 20, 50); grabs a sprite the dimensions of spriteName at x-20 and y-50, and sets it to spriteName, to be called later as a sprite