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

Author Topic: Setting sprite but displaying a white box, is this due to me using a reference  (Read 1373 times)

0 Members and 1 Guest are viewing this topic.

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Please read this post and adjust your problem description accordingly.

And read about the "white square problem" in the tutorials.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
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%