From b503e7e57b318dbef735d8cd667120cb1afd30bc Mon Sep 17 00:00:00 2001 From: nosch Date: Sun, 31 Aug 2025 01:28:13 +0200 Subject: [PATCH] made TextureAtlas a struct --- src/img/playersprite.png | Bin 0 -> 483 bytes src/render/textures.cpp | 32 +++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/img/playersprite.png diff --git a/src/img/playersprite.png b/src/img/playersprite.png new file mode 100644 index 0000000000000000000000000000000000000000..2393c707b69ec6ce12c3696ece91122d65f5a958 GIT binary patch literal 483 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D%z=X$z0hE&XX zJA17kv!h7s`w2=984n~mtaDgwAaQAefKJN?E*0Mbl|4*~A6U+^1z&b|2nh=27IIWg z3gk#w#$#RmKC|e&`s|xK)6dPBdG3ok&+1iz$G^C^^r=lw2raOZ&^M|1U3K5*^oCWl z=7nzD&-QQg+^K@vVy;E(@xOeeeRv|$uJCHi^z0TfV4O9#+_3qUW&+a%rVAGs&Ys(C zaVA5)V+O-pCRO8%LYXusovtl2Jy)Nea5MKqw!`IvJ9fT&?{Yil+WBSI69o?lMVL6e zKG8SF5i zya|IY123-ww}Uedp&jN2-h5|_dQ!(cMd^0KC8yI|(;L#Bf6Wj(_iomU=ik0Re;B=} m=yoa0J}l-P{C)qqJ!9JQ=$*c5hh2cN#^CAd=d#Wzp$Py|h{|06 literal 0 HcmV?d00001 diff --git a/src/render/textures.cpp b/src/render/textures.cpp index cff1139..879c4f9 100644 --- a/src/render/textures.cpp +++ b/src/render/textures.cpp @@ -1,11 +1,31 @@ #include "../../include/raylib-cpp.hpp" +#include #include using namespace std; -typedef vector TextureAtlas; typedef int ID; +struct TextureAtlas { + vector atlas; + + Texture GetTexture(ID id) { + if (atlas.size() >= id) { + return atlas[0]; + } + return atlas[id]; + } + + bool LoadImage(const char *path) { + atlas.push_back(LoadTexture(path)); + } + + bool AddTexture(Texture texture){ + atlas.push_back(texture); + } + +}; + Texture defaultTexture; void GenDefaultTexture(){ @@ -16,14 +36,8 @@ void GenDefaultTexture(){ TextureAtlas NewTextureAtlas() { TextureAtlas atlas; - atlas.push_back(defaultTexture); - + atlas.AddTexture(defaultTexture); return atlas; } -Texture GetTexture(ID id, TextureAtlas atlas) { - if (atlas.size() >= id) { - return atlas[0]; - } - return atlas[id]; -} +