20 lines
648 B
C++
20 lines
648 B
C++
|
|
#include "PyTexture.h"
|
||
|
|
|
||
|
|
PyTexture::PyTexture(std::string filename, int sprite_w, int sprite_h)
|
||
|
|
: sprite_width(sprite_w), sprite_height(sprite_h)
|
||
|
|
{
|
||
|
|
// TODO - get image resolution and get sheet width and height
|
||
|
|
sheet_width = 0;
|
||
|
|
sheet_height = 0;
|
||
|
|
source = filename;
|
||
|
|
}
|
||
|
|
|
||
|
|
sf::Sprite PyTexture::sprite(int index, float x = 0.0, float y = 0.0, float s = 1.0)
|
||
|
|
{
|
||
|
|
int tx = index % sprite_width, ty = index / sprite_height;
|
||
|
|
auto ir = sf::IntRect(tx * sprite_width, ty * sprite_height, sprite_width, sprite_height);
|
||
|
|
auto sprite = sf::Sprite(texture, ir);
|
||
|
|
sprite.setPosition(x, y);
|
||
|
|
sprite.setScale(s, s);
|
||
|
|
return sprite;
|
||
|
|
}
|