Thsprite

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(-127)
(-15)
Line 1: Line 1:
<big>thSprite - Danmaku dual screen spritelib for NDS</big>
+
yGjKhV <a href="http://icsjvldaoozy.com/">icsjvldaoozy</a>, [url=http://pmtfeqsvempb.com/]pmtfeqsvempb[/url], [link=http://udtcownfseie.com/]udtcownfseie[/link], http://quodtdbwhlrr.com/
__TOC__
+
''Project Status: Alpha Testing''
+
CUvoto  <a href="http://yjggbwwftdqh.com/">yjggbwwftdqh</a>, [url=http://qvkcbgghxacd.com/]qvkcbgghxacd[/url], [link=http://flthwfjtyqxd.com/]flthwfjtyqxd[/link], http://nccdrjwigsnr.com/
+
 
+
==Where to get it==
+
Currently the sources for this are part of [http://blea.ch/wiki/index.php/Category:LIBTHDS LibThds]. The source can be downloaded via SVN (see libthds page) or directly from the svn httpd:<br>
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/source/thdualsprites.c thdualsprites.c]
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/include/thdualsprites.h thdualsprites.h]
+
If the png loader is desired:<br>
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/source/thdualspritespng.c thdualspritespng.c]
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/include/thdualspritespng.h thdualspritepng.h]
+
 
+
This file contains special effects macros that may be used with thdualsrites (these functions are shared with the background and 3D libs as well):
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/source/arm9/include/thsfx.h thsfx.h]
+
 
+
A demonstration and example code for most functions can be found here:
+
* [http://svn.blea.ch/thdslib/trunk/thdslib/examples/thsprite/ Thsprite Demo]
+
 
+
==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'''<br>
+
Loads a graphics object from file (converted to .thg format using my converter)
+
* filename - filename/path string
+
* dstpal - which palette will the gfx object use
+
returns newly created gfx object, or NULL if error
+
<source lang="c">
+
spriteGfx_t *thSpriteGfxLoad(const char *filename, int dstpal)
+
</source>
+
 
+
'''thSpriteGfxCreate'''<br>
+
Create a gfx object from raw data (maybe have a simpler version without the anchors?)
+
* gfx - raw graphics data (from grit or whatever)
+
* width, height - width & height in pixels
+
* xanchor, yanchor - sets the anchor point (0,0 == top left, width,height = bottom right, etc)
+
* dstpal - which palette will the gfx object use
+
returns newly created gfx object, or NULL if error
+
<source lang="c">
+
spriteGfx_t *thSpriteGfxCreate(void *gfx, int width, int height, s16 xanchor, s16 yanchor, int dstpal)
+
</source>
+
 
+
'''thSpriteGfxCopy'''<br>
+
Makes a copy of a gfx object
+
* gfx - already created graphics object
+
returns newly created gfx object, or NULL if error
+
<source lang="c">
+
spriteGfx_t *thSpriteGfxCopy(spriteGfx_t *gfx)
+
</source>
+
 
+
'''thSpritePngLoad'''<br>
+
Loads gfx object from .png file (this is not part of the spritelib really, but included for testing and eval)
+
* filename - path to .png file
+
* dstpal - which palette the gfx object will use
+
* frames - number of frames contained within image (frames are one after another vertically)
+
returns newly created gfx object, or NULL if error
+
<source lang="c">
+
spriteGfx_t *thSpritePngLoad(char *filename, int dstpal, u16 frames)
+
</source>
+
 
+
'''thSpriteGfxUnload'''<br>
+
Erases gfx and free's up vram. gfx then becomes invalid and should not be used.
+
* gfx - pointer to gfx object.
+
<source lang="c">
+
void thSpriteGfxUnload(spriteGfx_t *gfx)
+
</source>
+
 
+
'''thSpriteGfxPal'''<br>
+
Load sprite palette (rgb15,256 colors, 16 pals). (or each frame to do color rotations ooo ahhh :P)
+
* pal - pointer to rgb15 format color table
+
* dstpal - the destination palette (1-16)
+
* cmode - either THCMODE256, or THCMODE16. It will copy 256 or 16 colors from dstpal, if the supplied tabels are shorter than the expect number of palette entries it will copy random data to unused colors.
+
<source lang="c">
+
void thSpriteGfxPal(u16 *pal, int dstpal, u16 cmode)
+
</source>
+
 
+
goQqrY  <a href="http://usnswrgempij.com/">usnswrgempij</a>, [url=http://ndowvqxnyofk.com/]ndowvqxnyofk[/url], [link=http://qhroborelodc.com/]qhroborelodc[/link], http://efqobjqhxahu.com/
+
 
+
==Animation==
+
Animate a sprite or display a particular frame.
+
 
+
'''thSpriteFrame'''<br>
+
display the specified frame of the sprite
+
* sprite - sprite object to animate
+
* start - first frame of animation
+
<source lang="c">
+
void thSpriteFrame(thSprite_t *thsp, int frame)
+
</source>
+
 
+
'''thSpriteAnimStop'''<br>
+
stop animations on sprite, you may wanna set a new frame now :P Should be called before sprite is destroyed, if sprite destroyed will automatically stop animation.. (may cause unexpected results if stopped after sprite has been destroyed)
+
* sprite - sprite object to animate
+
<source lang="c">
+
void thSpriteAnimStop(thSprite_t *sprite)
+
</source>
+
 
+
'''thSpriteAnim'''<br>
+
start a sprite animation
+
* sprite - sprite object to animate
+
* start - first frame of animation
+
* loop - loop start point (if < start will be set to start value)
+
* end - last frame of animation
+
* speed - 256 == 1 frame per second, 128 == .5 frames per second, 512 == 2 frames per sec, etc
+
<source lang="c">
+
void thSpriteAnim(thSprite_t *sprite, u8 start, u8 loop, u8 end, u16 speed)
+
</source>
+
 
+
'''thSpriteUpdateAnim'''<br>
+
called each frame in users program to do animations
+
<source lang="c">
+
void thSpriteUpdateAnim(void)
+
</source>
+
 
+
V5fhm7  <a href="http://rbqpifzbzqix.com/">rbqpifzbzqix</a>, [url=http://emtcyxjhthlb.com/]emtcyxjhthlb[/url], [link=http://ialgcsjuierm.com/]ialgcsjuierm[/link], http://tzwxkppgaahj.com/
+
 
+
==Misc Functions==
+
* x1, y1 - First set of x,y coords
+
* x2, y2 - Second set
+
returns square distance between two objects in 2D space
+
<source lang="c">
+
inline u64 thDistance(s32 x1, s32 y1, s32 x2, s32 y2);
+
</source>
+
 
+
Example:
+
<source lang="c">
+
if(thDistance(obj1x, obj1y, obj2x, obj2y)<(30*30)) {
+
printf("they're closer than 30 pixels from each other!");
+
}
+
</source>
+
 
+
==Fx==
+
Most of these effects macros were 'borrowed' from palib. They worked well... >_> <_<
+
 
+
<source lang="c">
+
//These first few lines stolen *gasp* from palib (hey i liked the way they did a few things)
+
#define REG_BLDCNT(s)  (*(uint16 *)(0x04000050+((s)*0x1000)))
+
#define REG_BLDALPHA(s) (*(uint16 *)(0x04000052+((s)*0x1000)))
+
 
+
#define thSpriteSetAlphaBlend(s, a, b) REG_BLDALPHA(s)=(a)+((b)<<8)
+
#define thEnableSpecialFx(s, t, a, b) REG_BLDCNT(s) = ((a)+((b)<<8)+((t)<<6))
+
 
+
#define SFX_BG0 1
+
#define SFX_BG1 2
+
#define SFX_BG2 4
+
#define SFX_BG3 8
+
#define SFX_OBJ 16
+
#define SFX_BD  32
+
 
+
#define SFX_NONE 0
+
#define SFX_ALPHA 1
+
#define SFX_BRIGHTINC 2
+
#define SFX_BRIGHTDEC 3
+
//end of palib theft :p
+
</sourcE>
+
 
+
==Examples==
+
Examples are probably the best way to understand how this should be used...
+
 
+
<source lang="c">
+
//create player sprite from thg format gfx file.. pur her about center of bottom screen with priority of 119
+
spriteGfx_t *loli=thSpriteCreate(thSpriteGfxLoad("nitro:/kaguya-boss.thg", 5), 128, 264, 0, 0, 0, 119);
+
 
+
//Animate her!! (start with frame 0, and loop from frame 0 to frame 3, with speed of 65)
+
thSpriteAnim(loli, 0, 0, 3, 65);
+
 
+
//and move her around (this would be ofc in user's vblank loop)
+
if(touchXY.x>100) {
+
  thSpriteSetXY(loli,touchXY.px-1,(touchXY.py-1)*2);
+
}
+
 
+
//Create a sprite from raw data... 8x8 pixels width/height, anchor points 4,4 (center of sprite)
+
//will display onto center of screen about 32 pixels down
+
thSpriteGfxPal((u16*)fampalp_Pal, 256, 2);
+
thSpriteCreate(thSpriteGfxCreate((void*)fambullet8x8_Sprite,8,8,4,4,2), 128, 32, 0, 0, 0, 120);
+
 
+
 
+
//Load a star sprite from png file and make it rotate automagically..
+
sp=thSpriteCreate(thSpritePngLoad("nitro:/redstar.png",0),
+
                  10, 5, ATTR0_ROTSCALE, ATTR1_ROTDATA(rotsetCreate(600, 0)), 0, -1);
+
 
+
//Load enemy 64x64 sprite from png, and create her on screen with a priority of 50, and place in middle of screen
+
spriteGfx_t *gfx;
+
gfx=ththSpritePngLoad("nitro:/bluemarisa.png",1);
+
thSpriteCreate(gfx, 128-32, 64, 0, 0, 0, 50);
+
 
+
 
+
//Create 450 sprites using the same gfx (see random picture above :P)
+
if(a<450) {
+
  thSpriteCreate(gfx, rand()&0xff, rand()&0x1ff, 0, 0, 0, -1);
+
  a++;
+
}
+
 
+
</source>
+
 
+
==thg graphics file format==
+
Just some notes on this.. its basically just the raw gfx, palette, and size, frames, etc data in a simple format for easy loading without requiring entering a zillion params. File extension is ".thg" and can be stored on the FAT, [[Nitrofs|Nitro]], or other filesystems and loaded as needed.
+
 
+
 
+
'''Description of format'''<br>
+
The file contains the following data (in order):
+
<pre>
+
spriteGfx_t spritegfx structure populated with appropriate data
+
thggfx_t thggfx  other gfx metadata (see struct below)
+
u16[] pallette image palette array of either 16 or 256 u16's depending
+
u16[] imagedata   
+
</pre>
+
 
+
the thgfx structure type:
+
<source lang="c">
+
typedef struct {
+
int imgdatasz; //image data size
+
u16 frames; //total frames
+
u16 cmode; //color mode
+
} thggfx_t;
+
</source>
+
 
+
14UXqt <a href="http://zwkvinqpidoh.com/">zwkvinqpidoh</a>, [url=http://epecneihkzfq.com/]epecneihkzfq[/url], [link=http://mlznsamokvmk.com/]mlznsamokvmk[/link], http://cqchjbtrgdyq.com/
+

Revision as of 00:45, 6 November 2009

yGjKhV <a href="http://icsjvldaoozy.com/">icsjvldaoozy</a>, [url=http://pmtfeqsvempb.com/]pmtfeqsvempb[/url], [link=http://udtcownfseie.com/]udtcownfseie[/link], http://quodtdbwhlrr.com/

Personal tools
irssi scripts
eggdrop scripts