mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 10:15:32 +00:00
fix posiion rescaling
This commit is contained in:
@@ -38,7 +38,7 @@ namespace RAY {
|
||||
static Window &getInstance();
|
||||
|
||||
//! @return A widow insta,ce. Only one window can be open at a time
|
||||
static Window &getInstance(int width, int height, const std::string &title, unsigned flags = FLAG_WINDOW_RESIZABLE, bool openNow = true) noexcept;
|
||||
static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true) noexcept;
|
||||
|
||||
//! @brief A window is movable.
|
||||
Window(Window &&) = default;
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace BBM
|
||||
void Runner::enableRaylib(WAL::Wal &wal)
|
||||
{
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman");
|
||||
RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||
wal.addSystem<AnimationsSystem>()
|
||||
.addSystem<AnimatorSystem>()
|
||||
.addSystem<RenderSystem>(window);
|
||||
|
||||
@@ -45,20 +45,14 @@ namespace BBM
|
||||
drawable.drawable->drawWiresOn(this->_window);
|
||||
}
|
||||
|
||||
void RenderSystem::rescaleDrawablePosition(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims)
|
||||
void RenderSystem::rescaleDrawablePosition(Vector3f &position, const Vector2f &newWinDims)
|
||||
{
|
||||
RAY::Vector2 newPosition;
|
||||
RAY::Vector2 oldPosition(drawable.getPosition());
|
||||
|
||||
newPosition.x = (oldPosition.x * newDims.x) / this->_previousDims.x;
|
||||
newPosition.y = (oldPosition.y * newDims.y) / this->_previousDims.y;
|
||||
|
||||
drawable.setPosition(newPosition);
|
||||
position.x = (position.x * newWinDims.x) / this->_previousDims.x;
|
||||
position.y = (position.y * newWinDims.y) / this->_previousDims.y;
|
||||
}
|
||||
|
||||
void RenderSystem::rescaleDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims)
|
||||
{
|
||||
this->rescaleDrawablePosition(drawable, newDims);
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(&drawable);
|
||||
|
||||
if (text) {
|
||||
@@ -86,7 +80,6 @@ namespace BBM
|
||||
if (newDims == this->_previousDims)
|
||||
return;
|
||||
newDims.y = (newDims.x * 720) / 1280;
|
||||
std::cout << newDims.x << " " << newDims.y << std::endl;
|
||||
this->_window.setDimensions(newDims);
|
||||
}
|
||||
|
||||
@@ -122,8 +115,10 @@ namespace BBM
|
||||
if (shader) {
|
||||
RAY::Shader::BeginUsingCustomShader(shader->getShader());
|
||||
}
|
||||
if (windowDimensions != this->_previousDims)
|
||||
if (windowDimensions != this->_previousDims) {
|
||||
this->rescaleDrawablePosition(pos.position, windowDimensions);
|
||||
this->rescaleDrawable(*drawable.drawable, windowDimensions);
|
||||
}
|
||||
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
if (shader) {
|
||||
|
||||
@@ -37,10 +37,10 @@ namespace BBM
|
||||
//! @param newDims the new window's dimensions
|
||||
void rescaleDrawable(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims);
|
||||
|
||||
//! @brief rescale the drawables position according to new window dimensions
|
||||
//! @param drawable the drawable to rescale position of
|
||||
//! @brief rescale the drawables position according to new window dimensions
|
||||
//! @param position a reference to position
|
||||
//! @param newDims the new window's dimensions
|
||||
void rescaleDrawablePosition(RAY::Drawables::ADrawable2D &drawable, const Vector2f &newDims);
|
||||
void rescaleDrawablePosition(Vector3f &position, const Vector2f &newWinDims);
|
||||
|
||||
void resizeWindow(Vector2f &newDims);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user