diff options
author | kdx <kikoodx@paranoici.org> | 2023-09-01 23:03:08 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-09-01 23:03:08 +0200 |
commit | 7bf9f5c5fc7cd8422070866744734fdcd937fbc8 (patch) | |
tree | 37b1eff50382e67131258690407ae2efb68fc3a3 | |
parent | 4ea628b8c6d500a803ed0c2c7d12718f57b41fa1 (diff) | |
download | px-7bf9f5c5fc7cd8422070866744734fdcd937fbc8.tar.gz |
spr center flag
-rw-r--r-- | src/px.c | 11 | ||||
-rw-r--r-- | src/px.h | 3 |
2 files changed, 11 insertions, 3 deletions
@@ -220,10 +220,17 @@ _pxSpr(const PxSprArgs *args) int h = (args->h < 0) ? (int)(args->spr->h) : (args->h); h = pxMin(h, args->spr->h - args->iy); + int ox = args->x; + int oy = args->y; + if (args->center) { + ox -= w / 2; + oy -= h / 2; + } + for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { - const int dx = x + args->x; - const int dy = y + args->y; + const int dx = x + ox; + const int dy = y + oy; int ix = args->ix + ((args->flip_x) ? (w - x - 1) : (x)); @@ -34,6 +34,7 @@ typedef struct { int h; bool flip_x; bool flip_y; + bool center; } PxSprArgs; typedef struct { @@ -94,7 +95,7 @@ void pxLine(int x0, int y0, int x1, int y1, PxCol col); /* Draw sprite. */ #define pxSpr(...) _pxSpr(&(const PxSprArgs){ \ .x=0, .y=0, .ix=0, .iy=0, .w=-1, .h=-1, .flip_x=false, .flip_x=false, \ - ._=0, __VA_ARGS__}) + .center=false, ._=0, __VA_ARGS__}) void _pxSpr(const PxSprArgs *args); /* Bind palette index to new color. */ |