rjDrawSprite2D - shaddatic/sa2b-render-fix GitHub Wiki

Prototype

void rjDrawSprite2D( const NJS_SPRITE* sp, Int n, Float pri, Uint32 attr )

API

void (*DrawSprite2D)( const NJS_SPRITE* sp, Int n, Float pri, Uint32 attr )

Ninja

void njDrawSprite2D( NJS_SPRITE* sp, Int n, Float pri, Uint32 attr )

Parameters

const NJS_SPRITE* sp

 Sprite structure

Int n

 Animation frame number

Float pri

 Sprite depth priority, in view space

Uint32 attr

 Sprite attribute flags

Flag Value Usage
NJD_SPRITE_ANGLE BIT_0 Rotate sprite around its center by the angle structure member
NJD_SPRITE_COLOR BIT_1 Use constant material color, otherwise white is used
NJD_SPRITE_HFLIP BIT_2 Flip sprite texture horizontally
NJD_SPRITE_VFLIP BIT_3 Flip sprite texture vertically
NJD_SPRITE_HVFLIP BIT_2|3 Flip sprite both horizontally and vertically
NJD_SPRITE_ALPHA BIT_5 Use translucency

Returns

No return value.

Description

Draw a sprite in 2D space.

Example

This example will draw a 64x64, opaque, sprite in the center of the screen at 10 meters away, and rotated by 90 degrees. It uses two frames of animation, and flips between them with every draw pass.

#define NUM_TEXANIM 2

#define NUM_TEX_0 0
#define NUM_TEX_1 2

NJS_TEXANIM tanim[NUM_TEXANIM] =
{
    // frame 1
    { 
        64, 64,    // sprite size
        32, 32,    // sprite center
        0, 0,      // top left texture coordinate
        256, 256,  // bottom right texture coordinate
        NUM_TEX_0, // texture number
        0x0        // reserved
    },
    // frame 2
    { 
        64, 64,    // sprite size
        32, 32,    // sprite center
        0, 0,      // top left texture coordinate
        256, 256,  // bottom right texture coordinate
        NUM_TEX_1, // texture number
        0x0        // reserved
    },
};

NJS_SPRITE sp =
{
    { 288.f, 208.f, 0.f }, // position, 'z' is ignored
    1.f, 1.f,              // scale multiplier
    NJM_DEG_ANG( 90.f ),   // rotate by 90 degrees
    &texlist,              // texlist
    tanim,                 // sprite animation list
};

// draw sprite 10m away, use angle
rjDrawSprite2D( &sp, n_frame, -100.f, NJD_SPRITE_ANGLE ); // <<<<<<<<

// next sprite frame
n_frame = (n_frame + 1) % NUM_TEXANIM;

Related Functions

History