commit f68b8f85d7c93f92a86f955654e13ad3efd04bc5
parent 8966ef1d28d84da97c7991b399fc294b1a2bde8f
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 18 Apr 2026 04:56:27 +0000
feat: draw scrolling background
Diffstat:
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -4,25 +4,37 @@
#define MainLoop emscripten_set_main_loop
+Texture2D background_texture;
+int scrollX = 0;
+
+void draw_background() {
+ if (!IsTextureValid(background_texture)) {
+ background_texture = LoadTexture("assets/sprites/background-day.png");
+ }
+
+ static const int scrollSpeed = 1;
+
+ scrollX -= scrollSpeed;
+
+ DrawTexture(background_texture, scrollX % 288, 0, WHITE);
+ DrawTexture(background_texture, (scrollX % 288) + 288, 0, WHITE);
+}
+
void draw(void) {
BeginDrawing();
- ClearBackground(RAYWHITE);
-
- DrawText(TextFormat("Hello World"), 190, 200, 20, DARKGRAY);
+ draw_background();
EndDrawing();
}
int main() {
static const char *title = "rayflap";
- static const int screenWidth = 640;
- static const int screenHeight = 960;
+ static const int screenWidth = 288;
+ static const int screenHeight = 512;
InitWindow(screenWidth, screenHeight, title);
- Texture2D texture = LoadTexture("assets/sprites/background-day.png");
-
MainLoop(draw, 60, 1);
return 0;