Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <string>
- #include <iostream>
- class AnimatedSprite : public sf::Transformable, public sf::Drawable
- {
- public:
- AnimatedSprite()
- {
- vertices.setPrimitiveType(sf::Quads);
- vertices.resize(4);
- texture = new sf::Texture();
- if (!texture->loadFromFile("assets/pokemon.png"))
- {
- std::cout << "ASDF\n";
- }
- auto frameBounds = sf::IntRect(0,0,16,16);
- vertices[0].position = sf::Vector2f(0,0);
- vertices[1].position = sf::Vector2f(0,frameBounds.height);
- vertices[2].position = sf::Vector2f(frameBounds.width, frameBounds.height);
- vertices[3].position = sf::Vector2f(frameBounds.width,0);
- float left = frameBounds.left;
- float right = frameBounds.left + frameBounds.width;
- float top = frameBounds.top;
- float bottom = frameBounds.top + frameBounds.height;
- vertices[0].texCoords = sf::Vector2f(left, bottom);
- vertices[1].texCoords = sf::Vector2f(left, top);
- vertices[2].texCoords = sf::Vector2f(right, top);
- vertices[3].texCoords = sf::Vector2f(right, bottom);
- }
- protected:
- virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
- {
- states.transform *= getTransform();
- states.texture = texture;
- target.draw(vertices, states);
- }
- sf::VertexArray vertices;
- sf::Texture *texture;
- };
- int main()
- {
- sf::RenderTexture renderTexture;
- renderTexture.create(160, 144);
- AnimatedSprite player;
- player.setPosition(0,0);
- renderTexture.draw(player);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement