Skip to content

Commit

Permalink
Fixed rendering of lord enemies
Browse files Browse the repository at this point in the history
Corrected scale factor to 1.5 (from 2.0) and fixed incorrect offset
  • Loading branch information
Marukyu committed May 6, 2016
1 parent 45dc448 commit b642384
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Client/LevelRenderer/ObjectAppearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <Shared/External/PugiXML/pugixml.hpp>
#include <Shared/Utils/MakeUnique.hpp>
#include <Shared/Utils/Utilities.hpp>
#include <Shared/Utils/VectorMul.hpp>
#include <algorithm>
#include <cmath>
#include <memory>
Expand Down Expand Up @@ -299,7 +300,7 @@ std::vector<sf::Vertex> 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)
Expand Down Expand Up @@ -642,14 +643,22 @@ 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<sf::Vertex> ObjectAppearanceManager::generateSpriteVertices(SpriteData spriteData) const
{
// Create vertex array.
std::vector<sf::Vertex> vertices;

// 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);
Expand All @@ -660,6 +669,12 @@ std::vector<sf::Vertex> 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);
Expand Down
1 change: 1 addition & 0 deletions src/Client/LevelRenderer/ObjectAppearance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class ObjectAppearanceManager

void onLoadObject(AppearanceLoader::Appearance appearance, std::map<ObjectID, ObjectAppearance> & target);

static void applyScaleFactor(sf::Vector2f & position, sf::Vector2f scaleFactor);
std::vector<sf::Vertex> generateSpriteVertices(SpriteData spriteData) const;

ITexturePacker * myPacker;
Expand Down

0 comments on commit b642384

Please sign in to comment.