sprites now support specifying flip
parent
ce4638d1e9
commit
89db4253ae
|
@ -84,7 +84,7 @@ void _exec_sprite_cmd(const drawcmd_t* cmd) {
|
||||||
SDL_FPoint origin = {destrect.w * sprite->origin.x, destrect.h * sprite->origin.y};
|
SDL_FPoint origin = {destrect.w * sprite->origin.x, destrect.h * sprite->origin.y};
|
||||||
SDL_RenderCopyExF(g_context.renderer, sprite->texture,
|
SDL_RenderCopyExF(g_context.renderer, sprite->texture,
|
||||||
&sprite->uv, &destrect, sprite->rot,
|
&sprite->uv, &destrect, sprite->rot,
|
||||||
&origin, SDL_FLIP_NONE);
|
&origin, sprite->flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -278,6 +278,7 @@ sprite_t render_text(const char* str, SDL_FRect area, text_style_t style) {
|
||||||
.x=area.x, .y=area.y,
|
.x=area.x, .y=area.y,
|
||||||
.texture=t,
|
.texture=t,
|
||||||
.uv=srcr,
|
.uv=srcr,
|
||||||
|
.flip=SDL_FLIP_NONE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return (sprite_t) {
|
return (sprite_t) {
|
||||||
|
@ -286,7 +287,8 @@ sprite_t render_text(const char* str, SDL_FRect area, text_style_t style) {
|
||||||
.sx=0, .sy=0,
|
.sx=0, .sy=0,
|
||||||
.texture=NULL,
|
.texture=NULL,
|
||||||
.uv={0,0,0,0},
|
.uv={0,0,0,0},
|
||||||
.x=0,.y=0
|
.x=0,.y=0,
|
||||||
|
.flip=SDL_FLIP_NONE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +445,8 @@ sprite_t make_sprite(const char* file, float x, float y) {
|
||||||
.sx=1.0,.sy=1.0,
|
.sx=1.0,.sy=1.0,
|
||||||
.rot=0,
|
.rot=0,
|
||||||
.depth=RLAYER_SPRITES,
|
.depth=RLAYER_SPRITES,
|
||||||
.uv=(SDL_Rect){0,0,0,0}
|
.uv=(SDL_Rect){0,0,0,0},
|
||||||
|
.flip=SDL_FLIP_NONE,
|
||||||
};
|
};
|
||||||
SDL_QueryTexture(sprite.texture, NULL, NULL, &sprite.uv.w, &sprite.uv.h);
|
SDL_QueryTexture(sprite.texture, NULL, NULL, &sprite.uv.w, &sprite.uv.h);
|
||||||
sprite.origin.x = -(float)sprite.uv.h/2.f; sprite.origin.y = -(float)sprite.uv.h/2.f;
|
sprite.origin.x = -(float)sprite.uv.h/2.f; sprite.origin.y = -(float)sprite.uv.h/2.f;
|
||||||
|
@ -460,6 +463,7 @@ sprite_t sprite_from_spritesheet(spritesheet_t *sheet, int index) {
|
||||||
.rot=0,
|
.rot=0,
|
||||||
.depth=RLAYER_SPRITES,
|
.depth=RLAYER_SPRITES,
|
||||||
.uv=rect,
|
.uv=rect,
|
||||||
|
.flip=SDL_FLIP_NONE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ typedef struct sprite_t {
|
||||||
float rot; // rotation around origin of the sprite
|
float rot; // rotation around origin of the sprite
|
||||||
depth_t depth; // depth to render at, lower is on top, higher is on bottom
|
depth_t depth; // depth to render at, lower is on top, higher is on bottom
|
||||||
SDL_Rect uv; // the source rect to render from the texture
|
SDL_Rect uv; // the source rect to render from the texture
|
||||||
|
SDL_RendererFlip flip; // the flipped state of the sprite
|
||||||
} sprite_t; // a drawable and transformable texture sprite
|
} sprite_t; // a drawable and transformable texture sprite
|
||||||
|
|
||||||
typedef struct rectshape_t {
|
typedef struct rectshape_t {
|
||||||
|
|
Loading…
Reference in New Issue