From b642384c79cfdaae4e745e1a7433f3cb2b87bfca Mon Sep 17 00:00:00 2001 From: Marukyu Date: Fri, 6 May 2016 18:52:54 +0200 Subject: [PATCH] Fixed rendering of lord enemies Corrected scale factor to 1.5 (from 2.0) and fixed incorrect offset --- src/Client/LevelRenderer/ObjectAppearance.cpp | 19 +++++++++++++++++-- src/Client/LevelRenderer/ObjectAppearance.hpp | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Client/LevelRenderer/ObjectAppearance.cpp b/src/Client/LevelRenderer/ObjectAppearance.cpp index 4aac76b..cd82310 100644 --- a/src/Client/LevelRenderer/ObjectAppearance.cpp +++ b/src/Client/LevelRenderer/ObjectAppearance.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -299,7 +300,7 @@ std::vector ObjectAppearanceManager::getObjectVertices(const Object& if (object.getPropertyInt(Object::Property::Lord) != 0) { - spriteData.scale *= 2.f; + spriteData.scale *= 1.5f; } } else if (object.getType() == Object::Type::Item) @@ -642,6 +643,14 @@ ObjectAppearanceManager::SpriteData::SpriteData() alpha = 1.f; } +void ObjectAppearanceManager::applyScaleFactor(sf::Vector2f & position, sf::Vector2f scaleFactor) +{ + static const sf::Vector2f offset = sf::Vector2f(0.5f, 1.f) * TILE_SIZE; + position -= offset; + position *= scaleFactor; + position += offset; +} + std::vector ObjectAppearanceManager::generateSpriteVertices(SpriteData spriteData) const { // Create vertex array. @@ -649,7 +658,7 @@ std::vector ObjectAppearanceManager::generateSpriteVertices(SpriteDa // Create vertex and texture rectangles. sf::IntRect texRect = myPacker->getImageRect(spriteData.nodeID); - sf::FloatRect vertRect(spriteData.offset.x, spriteData.offset.y, texRect.width * spriteData.scale.x, texRect.height * spriteData.scale.y); + sf::FloatRect vertRect(spriteData.offset.x, spriteData.offset.y, texRect.width, texRect.height); // Base vertex position. sf::Vector2f vp((sf::Vector2f(spriteData.position) - sf::Vector2f(0.5f, 1.f)) * TILE_SIZE); @@ -660,6 +669,12 @@ std::vector ObjectAppearanceManager::generateSpriteVertices(SpriteDa sf::Vector2f br(vertRect.left + vertRect.width, vertRect.top + vertRect.height); sf::Vector2f bl(vertRect.left, vertRect.top + vertRect.height); + // Apply scale to corners. + applyScaleFactor(tl, spriteData.scale); + applyScaleFactor(tr, spriteData.scale); + applyScaleFactor(br, spriteData.scale); + applyScaleFactor(bl, spriteData.scale); + // Texture corners. sf::Vector2f ttl(texRect.left, texRect.top); sf::Vector2f ttr(texRect.left + texRect.width, texRect.top); diff --git a/src/Client/LevelRenderer/ObjectAppearance.hpp b/src/Client/LevelRenderer/ObjectAppearance.hpp index fa7edc4..86bbcef 100644 --- a/src/Client/LevelRenderer/ObjectAppearance.hpp +++ b/src/Client/LevelRenderer/ObjectAppearance.hpp @@ -148,6 +148,7 @@ class ObjectAppearanceManager void onLoadObject(AppearanceLoader::Appearance appearance, std::map & target); + static void applyScaleFactor(sf::Vector2f & position, sf::Vector2f scaleFactor); std::vector generateSpriteVertices(SpriteData spriteData) const; ITexturePacker * myPacker;