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 - IntoTheBush

Pages: [1]
1
Graphics / passing texture through function
« on: December 23, 2011, 05:16:32 am »
Doh, thanks alot! You're my hero Turbine.  :D

2
Graphics / passing texture through function
« on: December 23, 2011, 01:10:31 am »
Alright, I switched from SDL to SFML a few days ago, compiled 2.0 libraries and am currently using that.

In my code I create a struct for a sprite and fill the information in with a given function.

Code: [Select]

uint cSpriteManager::CreateSprite(string File, float X, float Y, uint TotalFrames, uint TotalAnimations, uint FrameWidth, uint FrameHeight, Uint32 Delay, int Repeations)
{
     uint SpriteID = m_Sprites.size() + 1;
     sSprite NewSprite;

     NewSprite.nTexture = LoadTextureFile(File);
     NewSprite.Animation = CreateAnimation(TotalFrames, TotalAnimations, FrameWidth, FrameHeight, Delay, Repeations);
     NewSprite.X = X;
     NewSprite.Y = Y;
     m_Sprites[SpriteID] = NewSprite;

     return SpriteID;
}

Texture cSpriteManager::LoadTextureFile(string filename)
{
     Texture Temp;
     Temp.LoadFromFile(filename.c_str());

     if (!Temp.LoadFromFile(filename.c_str()))
     {
          cout << "cSpriteManager: Could Not Load File " << filename.c_str() << endl;
          exit(1);
     }

     Temp.SetSmooth(true);
     return Temp;
}


There is no problem with this, it returns the Temp texture and fills it into NewSprite.nTexture no problems, the problem is trying to access it. I define the container for all the sprites as:

Code: [Select]

private:
     map<uint, sSprite> m_Sprites;


 and I have a function that I call to return the texture to display, since it is private, which is:

Code: [Select]

Texture cSpriteManager::GetTexture(uint SpriteId)
{
     return m_Sprites[SpriteId].nTexture;
}


Once I have all my textures and information stored I run the following code:

Code: [Select]

Sprite.SetTexture(SpriteMan->GetTexture(SpriteId));


This just gives me a white shape where the sprite would display, but if I make the container public and call it with:
Code: [Select]

Sprite.SetTexture(SpriteMan->m_Sprites[SpriteId].nTexture);


It works just fine, I probably missed something very simple here, I was passing the Texture around when I first loaded it up, but it doesn't seem to be working now.  I just don't understand whats going on after tinkering for an hour or so. I would greatly appreciate any opinions on the matter.

Pages: [1]
anything