Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - CloakedYoshi

Pages: [1]
1
General / Trying to make sprites cleaner in code
« on: April 23, 2013, 09:40:43 am »
**Before ask for help, im a huge c++ noob, I just started taking classes for it, and figured i should start getting my feet wet by having some fun.**

So my issue is that if i want to make a 20+ sprites there is gonna be a very long list of my using

sf::Texture tex1;
sf::Texture tex2;
sf::Texture texN;

if (!tex1.loadFromFile("tex1.png"))
      return 1;
if (!tex2.loadFromFile("tex2.png"))
      return 1;
if (!texN.loadFromFile("texN.png"))

sf::Sprite spr1;
sf::Sprite spr2;
sf::Sprite sprN;

sprN.setTexture(texN);
ect...

since this action became so repetitive i figured their must be a way to make some kind of function... so i came up with this... which did not work because the i was declaring the textures and strings and sprites in the parameters... heres the fuction

void makeSprite(sf::Texture textureName, std::string fileName, sf::Sprite spriteName)
{
   sf::Texture(textureName);
   if (!textureName.loadFromFile(fileName))
      return;
   sf::Sprite spriteName;
   spriteName.setTexture(textureName);
}

am i on the right track, and just need to change something, or am I a total c++ newbie and i need to go a different direction/ i shouldnt even be doing this >.> thanks for the help! :P I hope i dont get raged at for being such a noob, my first post on the forum. This is more of a c++ language question then a SFML question but i think thats ok...

Pages: [1]
anything