How to use BeginMode2D() and Camera2D() #2370
Answered
by
TheAngriestCrusader
TheAngriestCrusader
asked this question in
Q&A
-
I can't seem to find out from anywhere how to actually use these two functions, can someone please explain them simply for me? I was going to make my own camera system but I saw that these functions existed and wanted to know if they'd save me time or not with my camera system. InitWindow(screenSize.x, screenSize.y, "Tower Defense Game");
SetExitKey(0);
Rectangle player = Rectangle{ 0, 0, 200, 200 };
while (!WindowShouldClose()) {
frameTime = GetFrameTime();
if (IsKeyDown(KEY_W)) {
player.y -= frameTime;
}
else if (IsKeyDown(KEY_A)) {
player.x -= frameTime;
}
else if (IsKeyDown(KEY_S)) {
player.y += frameTime;
}
else if (IsKeyDown(KEY_D)) {
player.x += frameTime;
}
camera.target = Vector2{ player.x + player.width / 2, player.y + player.height / 2 };
BeginDrawing();
ClearBackground(backgroundColor);
BeginMode2D(camera);
DrawRectangle(player.x, player.y, player.width, player.height, Color{ 255, 0, 0, 255 });
EndMode2D();
EndDrawing();
} |
Beta Was this translation helpful? Give feedback.
Answered by
TheAngriestCrusader
Mar 1, 2022
Replies: 1 comment
-
Turns out you have to define offset, rotation, and zoom. I thought they had default values. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
TheAngriestCrusader
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out you have to define offset, rotation, and zoom. I thought they had default values.