hi
i wrote an animation class.
the animation plays well but not where it should that seems to be drawn at coords * 2
can't find what i'm doing wrong. did cout to see coords in console and they are goods
minimal code representing a sprite
main.cpp
#include <SFML/Graphics/RenderWindow.hpp>
#include "bitmap/animation/animation.hpp"
#include "mysprite.hpp"
int main()
{
sf::RenderWindow window(sf::VideoMode(600, 600), "tests divers", sf::Style::Close);
MySprite mysprite;
mysprite.m_texture.loadFromFile("countdown.png");
sf::Vector2f coords(275,275);
mysprite.setPosition(coords);
sf::Vector2f framecoord = mysprite.getPosition();
float LeftX = framecoord.x;
float RightX = framecoord.x + 49;
float topY = framecoord.y;
float bottomY = framecoord.y + 49;
mysprite.m_frame[0].position = sf::Vector2f(LeftX, topY);
mysprite.m_frame[1].position = sf::Vector2f(RightX, topY);
mysprite.m_frame[2].position = sf::Vector2f(RightX, bottomY);
mysprite.m_frame[3].position = sf::Vector2f(LeftX, bottomY);
mysprite.m_frame[0].texCoords = sf::Vector2f(0, 0);
mysprite.m_frame[1].texCoords = sf::Vector2f(49, 0);
mysprite.m_frame[2].texCoords = sf::Vector2f(49, 49);
mysprite.m_frame[3].texCoords = sf::Vector2f(0, 49);
while(1) {
window.clear();
window.draw(mysprite);
window.display();
}
}
animation .cpp
#include "mysprite.hpp"
bool MySprite::loadTexture(std::string& fileName)
{
return m_texture.loadFromFile(fileName);
}
void MySprite::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
states.texture = &m_texture;
target.draw(m_frame, 4, sf::Quads, states);
}
animation.hpp
#ifndef MYSPRITE_CPP
#define MYSPRITE_CPP
#include <SFML/Graphics.hpp>
class MySprite : public sf::Drawable , public sf::Transformable {
public :
bool loadTexture(std::string& fileName);
sf::Vertex m_frame[4];
sf::Texture m_texture;
private :
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
};
#endif // MYSPRITE_CPP
image
https://ibb.co/Ry4TYN6