Out of scope

Now beginning on my first project that i actually want to do. And i instantly hit a road block and cant think of solutions because when i try to construct classes i can never get things to be in the "scope" that i want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Mario::setTexture(){
sf::Texture marioTexture;
if (!marioTexture.loadFromFile("Levels/Mario.png"))
{

}
sf::Sprite marioSprite; // <- declare mariosprite here
marioSprite.setTexture(marioTexture);

}
void Mario::setPosition(int a, int b){
x = a;
y = b;
marioSprite.setPosition(sf::Vector2f(x,y)); // <-- not accessible here
}

marioSprite was not declared in setposition. it was declared in settexture. But i don't know how to make it "declare" it for all of the class. the only solution i can think of is just like my usual solution. write noob code that's no class at all.
Last edited on
Why don't you have:

1
2
3
private:
    sf::Texture marioTexture;
    sf::Sprite marioSprite;


?

That way the texture+sprite all class functions can see an use, thought I have never used SMFL before, so you may want to wait upon other answers.
Why don't you have:

Because i had a really long night >.< that fixed it ... thanks
Very happy to help :)
Topic archived. No new replies allowed.