-
Notifications
You must be signed in to change notification settings - Fork 19
TextureAtlas
Kacper edited this page Jun 9, 2016
·
3 revisions
#TextureAtlas Klasa służąca do zarządzania głównie multiteksturami (atlasami tekstur), jednak sprawdza się także w przypadku pojedynczych tekstur i jest zalecana także w takiej konfiguracji (samodzielne sf::Texture nie będzie wspierane przez klasę ResourceManager).
Pełna definicja klasy znajduje się tutaj.
##Dostępne metody
Nazwa | Zwracany typ | Opis |
---|---|---|
TextureAtlas() | none | Konstruktor ustawiający podstawowe parametry na domyślne (count=0) |
LoadFromFile(path) | bool | Wczytuje teksturę z pliku, zwraca true jeżeli zakończone powodzeniem |
TrimByGrid(width, height) | bool | Width oraz Height to szerokość pojedynczej tekstury w pikselach. Dzieli jedną teksturę na atlas tekstur, true jeżeli jest to możliwe. |
GetCount() | size_t | Zwraca ilość tekstur w atlasie |
GetCellSizeX() | size_t | Zwraca szerokość pojedynczej tekstury |
GetCellSizeY() | size_t | Zwraca wysokość pojedynczej tekstury |
SetSpriteTextureByIndex(sprite, index) | void | Zmienia aktywną teksturę sprite'a na wczytaną do atlasu o podanym indeksie |
##Usage
TextureAtlas atlas; // stworzenie atlasu
if (!atlas.LoadFromFile("data/sample.png")) // wczytanie tekstury
{
cerr << "[!] Cannot load file!\n";
exit(1);
}
if (!atlas.TrimByGrid(64, 64)) // pocięcie jej na siatkę o komórkach: 64x64px
{
cerr << "[!] Cannot trim picture!\n";
exit(1);
}
int size = atlas.GetCount(); // pobranie ilości tekstur
sf::Sprite sprite;
for (int i=0; i<size; ++i)
{
atlas.SetSpriteTextureByIndex(sprite, i); // uboga "animacja"
sleep(2);
}