Thsprite

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(New page: ==What is this?== Atm this is just a stub detailing thdualsprites.c functionality. purpose is to create dual screen sprite engine for danmaku, curtain fire, bullet hell games. The document...)
 
Line 30: Line 30:
 
These functions deal with loading and managing graphics and palettes in vram. Most will return or take an object of type spriteGfx_t.
 
These functions deal with loading and managing graphics and palettes in vram. Most will return or take an object of type spriteGfx_t.
  
'''thSpriteGfxLoad'''
+
'''thSpriteGfxLoad''' - Loads a graphics object from file (converted to .thg format using my converter)
Loads a graphics object from file (converted to .thg format using my converter)
+
 
<source lang="c">
 
<source lang="c">
 
spriteGfx_t *thSpriteGfxLoad(const char *filename, int dstpal)
 
spriteGfx_t *thSpriteGfxLoad(const char *filename, int dstpal)
 
</source>
 
</source>
  
'''thSpriteGfxCreate'''
+
'''thSpriteGfxCreate''' - Create a gfx object from raw data
Create a gfx object from raw data
+
 
<source lang="c">
 
<source lang="c">
 
spriteGfx_t *thSpriteGfxCreate(void *gfx, int width, int height, int dstpal)
 
spriteGfx_t *thSpriteGfxCreate(void *gfx, int width, int height, int dstpal)
 
</source>
 
</source>
  
'''thSpriteGfxPal'''
+
'''thSpriteGfxPal''' -Load sprite palette (rgb15,256 colors, 16 pals). entries is the number of colors up to 256. (or each frame to do color rotations ooo ahhh :P)
Load sprite palette (rgb15,256 colors, 16 pals)
+
entries is the number of colors up to 256
+
(or each frame to do color rotations ooo ahhh :P)
+
 
<source lang="c">
 
<source lang="c">
 
void thSpriteGfxPal(u16 *pal, int entries, int dstpal)
 
void thSpriteGfxPal(u16 *pal, int entries, int dstpal)
 
</source>
 
</source>
  
'''thSpriteGfxCopy'''
+
'''thSpriteGfxCopy''' - Makes a copy of a gfx object
Makes a copy of a gfx object
+
 
<source lang="c">
 
<source lang="c">
 
spriteGfx_t *thSpriteGfxCopy(spriteGfx_t *gfx)
 
spriteGfx_t *thSpriteGfxCopy(spriteGfx_t *gfx)
 
</source>
 
</source>
  
'''thSpriteGfxClear'''
+
'''thSpriteGfxClear''' - Erases ALL sprites from obj mem starting with 'start'(since im loading a scene at a time this works best, can dynamically alloc later based on size and add thSpriteGfxUnload() mebbe?)
Erases ALL sprites from obj mem starting with 'start'(since im loading a scene at a time this works best, can dynamically alloc later based on size and add thSpriteGfxUnload() mebbe?)
+
 
<source lang="c">
 
<source lang="c">
 
void thSpriteGfxClear(int start)
 
void thSpriteGfxClear(int start)
Line 69: Line 62:
  
 
==Sprite Functions==
 
==Sprite Functions==
 +
'''thSpriteInit''' - Initalize thSprite system (and gfx)
 +
<source lang="c">
 +
void thSpriteInit(void)
 +
</source>
 +
 +
thSpriteCreate - create a sprite, returns sprite obj or NULL if error...
 +
<source lang="c">
 +
thSprite_t *thSpriteCreate(spriteGfx_t *gfx, int x, int y, u16 attr0, u16 attr1, u16 attr2, signed char priority)
 +
</source>
 +
 +
'''thSpriteDestroy''' - called by external functions to destory a created sprite, pass spriteHandle
 +
<source lang="c">
 +
int thSpriteDestroy(thSprite_t *thsp)
 +
</source>
 +
 +
'''thSpriteSetXY''' - Sets new x,y position first arg= sprite object
 +
<source lang="c">
 +
void thSpriteSetXY(thSprite_t *thsp, int x, int y)
 +
</source>
 +
 +
'''thSpriteSetAlpha''' - enables or disables alpha on a sprite
 +
<source lang="c">
 +
void thSpriteSetAlpha(thSprite_t *thsp, bool alpha)
 +
</source>
 +
 +
'''thSpriteUpdateRotset''' - changes which rotset is associated with a sprite
 +
<source lang="c">
 +
void thSpriteUpdateRotset(thSprite_t *thsp, unsigned char rotset)
 +
</source>
 +
 +
NOTE: these last four functions are things i need in my game and may not be in any librarys i publish. (in game where bullets may turn to bonus boxes the player can  collect and its easier to upadte just the gfx than deleting and creating hundreds of new bullets/sprites)
 +
 +
'''thSpriteUpdatePal''' - change which pallete a sprite uses
 +
<source lang="c">
 +
void thSpriteUpdatePal(thSprite_t *thsp, u8 pal)
 +
</source>
 +
 +
'''thSpriteUpdateGfx''' - update the image used by the sprite
 +
<source lang="c">
 +
void thSpriteUpdateGfx(thSprite_t *thsp, spriteGfx *gfx)
 +
</source>
 +
 +
'''thSpriteDiag''' - displays info such as memory used, number of active sprites etc, just for debugging...
 +
<source lang="c">
 +
void thSpriteDiag(void)
 +
</source>
 +
 +
'''thSpriteUpdateGfxPal''' - /update the image used by the sprite
 +
<source lang="c">
 +
void thSpriteUpdateGfxPal(thSprite_t *thsp, spriteGfx *gfx,u8 pal)
 +
</source>
 +
 +
==Animation==
 +
'''thSpriteFrame''' - display the specified frame of the sprite
 +
<source lang="c">
 +
void thSpriteFrame(thSprite_t *thsp, int frame)
 +
</source>
 +
 +
'''thSpriteAnimStop''' - stop animations on sprite, you may wanna set a new frame now :P
 +
<source lang="c">
 +
void thSpriteAnimStop(thSprite_t *sprite)
 +
</source>
 +
 +
'''thSpriteAnim''' - start a sprite animation
 +
<source lang="c">
 +
void thSpriteAnim(thSprite_t *sprite, u8 start, u8 loop, u8 end, u16 speed)
 +
</source>
 +
 +
'''thSpriteUpdateAnim''' - called each frame in users program to do animations
 +
<source lang="c">
 +
void thSpriteUpdateAnim(void)
 +
</source>
 +
 +
==Rotation==
 +
'''rotsetInit''' - init rotsets, tho this should prolly be called from spriteInit() eh?
 +
<source lang="c">
 +
void rotsetInit(void)
 +
</source>
 +
 +
'''rotSet''' - change rotset params
 +
<source lang="c">
 +
void rotSet(int rotset, u16 angle, int xmag, int ymag)
 +
</source>
 +
 +
'''rotSetNoZoom''' - same as above without magnify
 +
<source lang="c">
 +
void rotSetNoZoom(int rotset, u16 angle)
 +
</source>
 +
 +
rotsetCreate - allocate a rotset, and start automagic rotation.. if spd and angle are set.. returns a rotset you can apply to a sprite
 +
<source lang="c">
 +
u8 rotsetCreate(int spd, u32 angle)
 +
</source>
 +
 +
'''rotsetDestroy''' - dealloc rotset
 +
<source lang="c">
 +
void rotsetDestroy(u8 rotset)
 +
</source>
 +
 +
'''rotsetUpdate''' - called each frame to update automagic rotations
 +
<source lang="c">
 +
void rotsetUpdate()
 +
</source>

Revision as of 10:21, 27 June 2008

Contents

What is this?

Atm this is just a stub detailing thdualsprites.c functionality. purpose is to create dual screen sprite engine for danmaku, curtain fire, bullet hell games. The documentation is completely unfinished as is the library. Most features are supported already however.

should have the following features:

  • treats both screens as one long 384px high screen
  • be able to multiplex sprites giving up to 1024 sprites total (tho limited to 128 sprites in any of 8 48px high vertical blocks)
  • dynamically created/destroyed sprites
  • efficient use of hardware sprites only allocating sprite for which screen it can be viewed on
  • auto deallocation of hardware sprites that are not visible and reallocation if returned to screen
  • loose priority system, tries to give u whatever priority u request or closest match.. -1 = psuedo random priority

Types

User should typically not touch the data contained within these types...

spriteGfx_t - graphics object data and information.

  • size - in pixels, only using width atm because all my sprites are square, but will soon add x,y sizes
  • attr1 - size in attr1 format or any other attr1 info
  • attr2 - palette to use, again already in attr2 format
  • framesize - how many tiles make up 1 frame

thSprite_t - sprite object information..

  • which gfx object does this sprite use
  • attr0
  • attr1
  • attr2 - these are ofc the preformated attribs
  • ani - used to associate an animation object with this sprite


Gfx functions

These functions deal with loading and managing graphics and palettes in vram. Most will return or take an object of type spriteGfx_t.

thSpriteGfxLoad - Loads a graphics object from file (converted to .thg format using my converter)

spriteGfx_t *thSpriteGfxLoad(const char *filename, int dstpal)

thSpriteGfxCreate - Create a gfx object from raw data

spriteGfx_t *thSpriteGfxCreate(void *gfx, int width, int height, int dstpal)

thSpriteGfxPal -Load sprite palette (rgb15,256 colors, 16 pals). entries is the number of colors up to 256. (or each frame to do color rotations ooo ahhh :P)

void thSpriteGfxPal(u16 *pal, int entries, int dstpal)

thSpriteGfxCopy - Makes a copy of a gfx object

spriteGfx_t *thSpriteGfxCopy(spriteGfx_t *gfx)

thSpriteGfxClear - Erases ALL sprites from obj mem starting with 'start'(since im loading a scene at a time this works best, can dynamically alloc later based on size and add thSpriteGfxUnload() mebbe?)

void thSpriteGfxClear(int start)

thSpritePngLoad Loads gfx object from .png file (this is not part of the spritelib really, but included for testing and eval)

spriteGfx_t *thSpritePngLoad(char *filename, int dstpal)

Sprite Functions

thSpriteInit - Initalize thSprite system (and gfx)

void thSpriteInit(void)

thSpriteCreate - create a sprite, returns sprite obj or NULL if error...

thSprite_t *thSpriteCreate(spriteGfx_t *gfx, int x, int y, u16 attr0, u16 attr1, u16 attr2, signed char priority)

thSpriteDestroy - called by external functions to destory a created sprite, pass spriteHandle

int thSpriteDestroy(thSprite_t *thsp)

thSpriteSetXY - Sets new x,y position first arg= sprite object

void thSpriteSetXY(thSprite_t *thsp, int x, int y)

thSpriteSetAlpha - enables or disables alpha on a sprite

void thSpriteSetAlpha(thSprite_t *thsp, bool alpha)

thSpriteUpdateRotset - changes which rotset is associated with a sprite

void thSpriteUpdateRotset(thSprite_t *thsp, unsigned char rotset)

NOTE: these last four functions are things i need in my game and may not be in any librarys i publish. (in game where bullets may turn to bonus boxes the player can collect and its easier to upadte just the gfx than deleting and creating hundreds of new bullets/sprites)

thSpriteUpdatePal - change which pallete a sprite uses

void thSpriteUpdatePal(thSprite_t *thsp, u8 pal)

thSpriteUpdateGfx - update the image used by the sprite

void thSpriteUpdateGfx(thSprite_t *thsp, spriteGfx *gfx)

thSpriteDiag - displays info such as memory used, number of active sprites etc, just for debugging...

void thSpriteDiag(void)

thSpriteUpdateGfxPal - /update the image used by the sprite

void thSpriteUpdateGfxPal(thSprite_t *thsp, spriteGfx *gfx,u8 pal)

Animation

thSpriteFrame - display the specified frame of the sprite

void thSpriteFrame(thSprite_t *thsp, int frame)

thSpriteAnimStop - stop animations on sprite, you may wanna set a new frame now :P

void thSpriteAnimStop(thSprite_t *sprite)

thSpriteAnim - start a sprite animation

void thSpriteAnim(thSprite_t *sprite, u8 start, u8 loop, u8 end, u16 speed)

thSpriteUpdateAnim - called each frame in users program to do animations

void thSpriteUpdateAnim(void)

Rotation

rotsetInit - init rotsets, tho this should prolly be called from spriteInit() eh?

void rotsetInit(void)

rotSet - change rotset params

void rotSet(int rotset, u16 angle, int xmag, int ymag)

rotSetNoZoom - same as above without magnify

void rotSetNoZoom(int rotset, u16 angle)

rotsetCreate - allocate a rotset, and start automagic rotation.. if spd and angle are set.. returns a rotset you can apply to a sprite

u8 rotsetCreate(int spd, u32 angle)

rotsetDestroy - dealloc rotset

void rotsetDestroy(u8 rotset)

rotsetUpdate - called each frame to update automagic rotations

void rotsetUpdate()
Personal tools
irssi scripts
eggdrop scripts