Initial PyTexture class
no testing done. should enable rectangular (non-square) textures "sprite" method; let's just overwrite sprites with texture coords Hoping to replace awful code like: `self->data->sprite.sprite.setTextureRect(self->data->sprite.itex->spriteCoordinates(val));` with something like: `self->data->sprite = self->data->texture->sprite(val);`
This commit is contained in:
parent
cdaf309272
commit
47d0e34a17
|
@ -0,0 +1,20 @@
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
#include "Common.h"
|
||||||
|
#include "Python.h"
|
||||||
|
|
||||||
|
class PyTexture
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
sf::Texture texture;
|
||||||
|
std::string source;
|
||||||
|
int sprite_width, sprite_height, sheet_width, sheet_height;
|
||||||
|
public:
|
||||||
|
PyTexture(std::string filename, int sprite_w, int sprite_h);
|
||||||
|
sf::Sprite sprite(int index, float x = 0.0, float y = 0.0, float s = 1.0);
|
||||||
|
};
|
Loading…
Reference in New Issue