commit a9a9cdb9
Add tiling background
Changed files
| M | data/sprites/background.sprite before |
| A | data/textures/background.png |
| M | src/PuzzleSingleImageState.cpp before |
| M | src/sago_common.cpp before |
| M | src/sago_common.hpp before |
diff --git a/data/sprites/background.sprite b/data/sprites/background.sprite
index df5cd46..a88b1a3 100644
--- a/data/sprites/background.sprite
+++ b/data/sprites/background.sprite
@@ -7,5 +7,14 @@
"width" : 1364,
"number_of_frames" : 1,
"frame_time" : 1
+},
+"background_tile" : {
+ "texture" : "background",
+ "topx" : 0,
+ "topy" : 0,
+ "height" : 150,
+ "width" : 150,
+ "number_of_frames" : 1,
+ "frame_time" : 1
}
}
diff --git a/data/textures/background.png b/data/textures/background.png
new file mode 100755
index 0000000..4040de3
Binary files /dev/null and b/data/textures/background.png differ
diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp
index 8f2426c..056218d 100644
--- a/src/PuzzleSingleImageState.cpp
+++ b/src/PuzzleSingleImageState.cpp
@@ -69,7 +69,6 @@ void PuzzleSingleImageState::ProcessInput(const SDL_Event& event, bool &processe
}
void PuzzleSingleImageState::Draw(SDL_Renderer* target) {
- globalData.spriteHolder->GetSprite("background_sixteen_nine").Draw(target, SDL_GetTicks(), 0, 0);
SDL_Rect rect;
rect.x = globalData.xsize/2-resized_image_physical_width/2;
rect.y = globalData.ysize/2-resized_image_physical_height/2;
diff --git a/src/sago_common.cpp b/src/sago_common.cpp
index 5674612..c7c5d16 100644
--- a/src/sago_common.cpp
+++ b/src/sago_common.cpp
@@ -38,7 +38,8 @@ void RunGameState(sago::GameStateInterface& state ) {
bool done = false; //We are done!
while (!done && !globalData.isShuttingDown) {
SDL_SetRenderDrawColor(globalData.screen, 0, 0, 0, 255);
- SDL_RenderClear(globalData.screen);
+ //SDL_RenderClear(globalData.screen);
+ DrawBackground(globalData.screen);
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
@@ -93,6 +94,31 @@ void RunGameState(sago::GameStateInterface& state ) {
}
}
+void DrawBackground(SDL_Renderer* target) {
+ SDL_RenderClear(target);
+ sago::SagoSprite background = globalData.spriteHolder->GetSprite("background_tile");
+ size_t ticks = SDL_GetTicks();
+ if (true) {
+ int nextX = 0;
+ if (true) {
+ nextX -= (ticks/100)%background.GetWidth();
+ }
+ while (nextX < globalData.xsize) {
+ int nextY = 0;
+ if (true) {
+ nextY -= (ticks/100)%background.GetWidth();
+ }
+ while (nextY < globalData.ysize) {
+ background.Draw(target, ticks, nextX, nextY);
+ nextY += background.GetHeight();
+ }
+ nextX += background.GetWidth();
+ }
+ return;
+ }
+ background.DrawScaled(target, ticks, 0, 0, globalData.xsize, globalData.ysize);
+}
+
/**
* This function reads the mouse coordinates from a relevant event.
* Unlike SDL_GetMouseState this works even if SDL_RenderSetLogicalSize is used
diff --git a/src/sago_common.hpp b/src/sago_common.hpp
index 4431eea..c7d180a 100644
--- a/src/sago_common.hpp
+++ b/src/sago_common.hpp
@@ -30,6 +30,7 @@ void RunGameState(sago::GameStateInterface& state );
void UpdateMouseCoordinates(const SDL_Event& event, int& mousex, int& mousey);
void InitGame();
void UninitGame();
+void DrawBackground(SDL_Renderer* target);
#endif /* SAGO_COMMON_HPP */