Skip to content

Components Sprites

ImOverlord edited this page Jan 23, 2019 · 9 revisions

Sprites

Sprite Struct

typedef struct bs_sprite_s
{
char *id_sprite;
sfSprite *sprite;
sfTexture *texture;
sfVector2i size;
sfVector2f offset;
sfVector2f pos;
sfVector2f pos_s;
sfVector2f scale;
sfVector2f speed;
bool is_init;
bool enabled;
char *curr_anim;
bs_list_t *anims;
sfRenderStates *rs;
} bs_sprite_t;

id_sprite: Is an unique indetifier.
sprite: SFML sprite.
texture: SFML texture.
size: Size of the sprite.
offset: set the offset of the sprite.
pos: position of the sprite.
pos_s: ?.
scale: scale of the sprite.
speed: mouvement speed of the sprite.
is_init: Internal value for the sprite renderer (shouldn't be modified but the user).
enabled: Boolean for if the sprite should be rendered.
cur_anime: Animation name that is being played.
anims: List of anims connected to the sprite.
rs: var to handle shaders.

Sprite Functions

bool bs_sprite_add_to_scene(bs_scene_t *scene, bs_sprite_t *sprite)
Adds sprite to a specified scene.
scene: Scene where the sprite should be added.
sprite: Sprite to add to the scene.

bs_sprite_t *bs_sprite_create(char *id, const char *texture_path)
Creates and populate the bs_sprite_s struct.
id: Unique identifier for the sprite.
texture_path: path to the texture.

bs_sprite_t *bs_sprite_get_by_id(bs_scene_t *scene, char *id)
Returns a sprite with specified id.
scene: where the sprite should be located.
id: Unique identifier of the sprite.

bool bs_sprite_render(bs_frame_t *frame, bs_sprite_t *sprite)
Renders a sprite.
frame: Frame where the Sprite should be rendered.
sprite: Sprite to render.

bool bs_sprite_set_pos(bs_sprite_t *sprite, float x, float y)
Sets the sprite position.
sprite: Sprite that should be affected.
x: new x position.
y: new y position.

bool bs_sprite_set_offset(bs_sprite_t *sprite, float offset_x, float offset_y)
Sets the sprite offset.
sprite: Sprite to be affected.
x: new x offset.
y: new y offset.

bool bs_sprite_set_scale(bs_sprite_t *sprite, float x, float y) Sets the sprite scale.
sprite: Sprite to be affected.
x: new x scale.
y: new y scale.

bool bs_sprite_set_size(bs_sprite_t *sprite, int x, int y)
Sets the sprite's size.
sprite: Sprite to be affected.
x: new width.
y: new height.

bool bs_sprite_set_speed(bs_sprite_t *sprite, float x, float y)
Sets the sprite's speed.
sprite: Sprite to be affected.
x: new x speed.
y: new y speed.

void bs_sprite_destroy(bs_sprite_t *sprite)
Destroys sprite.
sprite: Sprite to be destroyed.

Clone this wiki locally