added rest of basics in TSE_Core
This commit is contained in:
35
TSE_Core/src/elements/TileSet.cpp
Normal file
35
TSE_Core/src/elements/TileSet.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "TileSet.hpp"
|
||||
#include "Debug.hpp"
|
||||
|
||||
#define PADDING 0.0f
|
||||
|
||||
TSE::TileSet::TileSet(Texture *tex, int x, int y)
|
||||
{
|
||||
SetTexture(tex);
|
||||
SetCount(x,y);
|
||||
}
|
||||
|
||||
void TSE::TileSet::SetCount(int x, int y)
|
||||
{
|
||||
resx = x;
|
||||
resy = y;
|
||||
}
|
||||
|
||||
void TSE::TileSet::SetTexture(Texture *tex)
|
||||
{
|
||||
this->tex = tex;
|
||||
}
|
||||
|
||||
void TSE::TileSet::GetSpriteAt(int x, int y, Sprite &s)
|
||||
{
|
||||
if(x < 0 || x >= resx || y < 0 || y >= resy)
|
||||
{
|
||||
TSE_ERROR("The sprite you are trying to access is out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 startpos = Vector2(((tex->size().x / resx) * (x + PADDING)) / tex->size().x, ((tex->size().y / resy) * (y + PADDING)) / tex->size().y);
|
||||
Vector2 endpos = Vector2(((tex->size().x / resx) * ((x + 1) - PADDING)) / tex->size().x, ((tex->size().y / resy) * ((y + 1) - PADDING)) / tex->size().y);
|
||||
|
||||
s = Sprite(tex, Rect(startpos, endpos));
|
||||
}
|
||||
Reference in New Issue
Block a user