Table of Contents

 
AddSprite
 

Purpose

Adds a new sprite object to the manager

 

Protoype

void CSpriteMngr::AddSprite (string str_sprite_id, string str_image_id, bool b_show, string str_current_anim, 
                             int i_sprite_x, int i_sprite_y)
 

Parameters

sprite_id the ID of the new sprite object
image_id the ID of the image object containing the sprite's animation template
show whether to show (TRUE) or hide (FALSE) the sprite upon creation
current_anim the animation to load in upon creation
sprite_x the X location of the sprite
sprite_y the Y location of the sprite
 

Description

This function adds a new sprite object with the unique identifier passed in for str_sprite_id. If there is already a copy of the sprite ID in the manager then the new sprite object will not be added. Each sprite object must have an accompanying image ID pass in via str_image_id that points to the image holding the sprite's animation template This template contains the various frames of animation used to animate the sprite. Use b_show to decide whether you want to show (TRUE) or hide (FALSE) the sprite when it is created. The value of str_current_anim is the ID of a current or future animation sequence. If you were to lock this sprite object and play its animation after creating it, the sequence you passed in for str_current_anim would play - or toss an error if the sequence ID does not yet exist. If you wish to have no default animation, use NO_ANIM. Finally, to place the sprite on the screen you use the last two parameters, i_sprite_x and i_sprite_y.

NOTE: When using the tile engine, the render function will automatically bind the sprite objects to the map and thus automatically set their locations relative to the map location

Layering Sprites

If you want one sprite to appear atop of another, then you can use the manager's sorting ability. Simply adopt the naming convention of #_spritename where # is the layer number of the sprite. So say you have two sprites - spriteA and spriteB. If you want spriteA to be able to appear on top of spriteB then you would rename them 0_spriteA and 1_spriteB. If you wanted to place spriteC in between the two, you would rename them all 0_spriteA, 1_spriteC and 2_spriteB.

 
Use
CSpriteMngr sprite;
sprite.AddSprite("my_sprite", "sprite_template", true, NO_ANIM, 50, 50);
 

Prev: AddAnimation
Next: Assign