mirror of
https://github.com/haya3218/SDfmL.git
synced 2024-08-14 23:57:09 +00:00
easier centering
This commit is contained in:
parent
6ffff01ac7
commit
ad034794d6
3 changed files with 24 additions and 1 deletions
|
@ -34,7 +34,7 @@ class MainState : public State {
|
|||
|
||||
title.scale.y = sin(elaped);
|
||||
|
||||
title.y = (480.0/2) - (title.h*title.scale.y/2);
|
||||
title.centerSelf();
|
||||
|
||||
elaped += 0.01;
|
||||
}
|
||||
|
|
|
@ -79,6 +79,21 @@ void Render::Object::Draw(float dt) {
|
|||
_sc_h = _h-cam_rect.h;
|
||||
}
|
||||
|
||||
void Render::Object::centerSelf(AXIS axis) {
|
||||
switch (axis) {
|
||||
case X:
|
||||
x = (WINDOW_WIDTH/2) - (w*scale.x/2);
|
||||
break;
|
||||
case Y:
|
||||
y = (WINDOW_HEIGHT/2) - (h*scale.y/2);
|
||||
break;
|
||||
case XY:
|
||||
x = (WINDOW_WIDTH/2) - (w*scale.x/2);
|
||||
y = (WINDOW_HEIGHT/2) - (h*scale.y/2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Render::Init(string window_name) {
|
||||
consoleD = GetConsoleWindow();
|
||||
SetWindowTextA(consoleD, "Logging window");
|
||||
|
|
|
@ -24,6 +24,12 @@ struct Vector2
|
|||
float y = 1;
|
||||
};
|
||||
|
||||
enum AXIS {
|
||||
X,
|
||||
Y,
|
||||
XY
|
||||
};
|
||||
|
||||
namespace Render {
|
||||
extern SDL_Window* window;
|
||||
extern SDL_Renderer* renderer;
|
||||
|
@ -54,6 +60,8 @@ namespace Render {
|
|||
int _sc_x, _sc_y, _sc_w, _sc_h;
|
||||
SDL_Texture* _tex = nullptr;
|
||||
void set_property(string name, bool value);
|
||||
|
||||
void centerSelf(AXIS axis = XY);
|
||||
private:
|
||||
int _x, _y, _w, _h;
|
||||
int _ori_w, _ori_h;
|
||||
|
|
Loading…
Reference in a new issue