Adding some clarification on offsets
@@ -217,7 +217,7 @@ ENGINE_init(ENGINE* engine) {
engine->debug.errorBuf = NULL;
engine->debug.errorBufLen = 0;
-
+ // Initialise the canvas offset.
engine->offsetX = 0;
engine->offsetY = 0;
engine->width = GAME_WIDTH;
@@ -340,9 +340,12 @@ ENGINE_pget(ENGINE* engine, int64_t x, int64_t y) {
}
inline internal void
ENGINE_pset(ENGINE* engine, int64_t x, int64_t y, uint32_t c) {
- // Draw pixel at (x,y)
+
+ // Account for canvas offset
x += engine->offsetX;
y += engine->offsetY;
+
+ // Draw pixel at (x,y)
int32_t width = engine->width;
int32_t height = engine->height;
if ((c & (0xFF << 24)) == 0) {
@@ -378,8 +381,11 @@ ENGINE_pset(ENGINE* engine, int64_t x, int64_t y, uint32_t c) {
internal void
ENGINE_blitBuffer(ENGINE* engine, int32_t x, int32_t y) {
PIXEL_BUFFER buffer = engine->blitBuffer;
+
+ // Account for Canvas offset
x += engine->offsetX;
y += engine->offsetY;
+
uint32_t* blitBuffer = buffer.pixels;
for (size_t j = 0; j < buffer.height; j++) {
for (size_t i = 0; i < buffer.width; i++) {
