SFML community forums

Help => General => Topic started by: Canvas on September 29, 2014, 09:40:32 pm

Title: Setting sprite but displaying a white box, is this due to me using a reference
Post by: Canvas on September 29, 2014, 09:40:32 pm
Hello there,

Ok bare with me on this one, I have myself a class which is a ImageLoader which basically storing a map of sf::Texture, I also have a class which is LevelState.

Now on the construction of my LevelState it required that two references are initialized on the constructor like so

Header snippet

...
public:
LevelState(FontLoader& fontLoader, ImageLoader& imageLoader);
...
private:

        ImageLoader& _imageLoader;
        FontLoader& _fontLoader;
...

Class snippet
LevelState::LevelState(FontLoader& fontLoader, ImageLoader& imageLoader) : _fontLoader(fontLoader), _imageLoader(imageLoader)
{

}

now this is working fine however it only works for some of my classes, I have a method called Setup which uses my imageLoader like so

UISprite.setTexture(imageLoader.Images[ImageNames::L_UI]);
 

and when asking to draw that it renders perfectly. however it doesn't work for my other class.

Here is a class that works fine

LevelState::Setup
DisplayObject displayObject;
        DisplayObjects.push_back(displayObject);
        DisplayObjects.at(0).Setup(0, 0, imageLoader.Images[ImageNames::Background1]);

//SETUP METHOD FOR DisplayObject
void DisplayObject::Setup(int xSet, int ySet, sf::Texture& spriteSet)
{
        XPos = xSet;
        YPos = ySet;
        Sprite.setTexture(spriteSet);
        Sprite.setPosition(XPos, YPos);
}
//
 

My DisplayObject renders without a problem

My Enemy class however is always a white block

Enemy enemy;
                Row1Enemies.push_back(enemy);
                Row1Enemies[0].Setup(75, 25, _imageLoader.Images[ImageNames::L_Enemy2], EnemyType::Shooter, 0.3, 1);

//ENEMY SETUP METHOD
void Enemy::Setup(int xSet, int ySet, sf::Texture spriteSet, EnemyType type, int fireChance, int lifeSet)
{
        XPos = xSet;
        YPos = ySet;
        Sprite.setTexture(spriteSet);
        Type = type;
        Status = true;
        FireChance = fireChance;
        Life = lifeSet;
}
//
 

Why on earth does my displayobject render fine and my enemy doesn't? Can anyone help me out here?
Title: Re: Setting sprite but displaying a white box, is this due to me using a reference
Post by: Nexus on September 29, 2014, 09:41:51 pm
Please read this post (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368) and adjust your problem description accordingly.

And read about the "white square problem" in the tutorials.
Title: Re: Setting sprite but displaying a white box, is this due to me using a reference
Post by: Canvas on September 29, 2014, 09:42:17 pm
Can this be removed please I know the problem, I wasn't passing my sf::Texture as a reference to my enemy, passing a reference works 100%