REally need help passing SFML sprites by reference to main loop

Surprisingly, a lot of SFML documentation on drawing to graphics only seems to cover declaring images glabaly,

Im trying to create a sprite wrapper so I can draw objects in the main loop without as much clutter, I have only a couple of weeks to re-create a bomberman game and while im aware my objects are out of scope but I just cannot re-learn passing by reference fast enough online, i think im in real trouble!

I read a lot of documentation and watched a lot of youtube videos, im using SFML 2.0.

here is some code...

this is in Sprites.cpp...I must change the name so it doesn't clash with sf::SPrites

1
2
3
4
5
6
7
8
9
10
11
//constructor
Sprites::Sprites(std::string _path): path( _path){

 if(setImage()){

    std::cout << "Image @" << path << " loaded." << std::endl;
 }else{

    std::cout << "Image @   " << path << " failed." << std::endl;
 }
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool Sprites::setImage(){

    if (cntSheet.loadFromFile(path)){

        tex.update(cntSheet);
        sprite.setTexture(tex);
        return true;
    }else{

        return false;
    }

}


I need to return the Sprite some how I tried many variations of this, and much like it, as i recall I just need to pass a reference to the image in themain loop, im getting no luck at all however, i tried a few things with temporary variables but im sooo rusty.

1
2
3
4
5
sf::Sprite Sprites::returnSprite(){

            return &sprite;
        }


of course, in main this doesnt work

1
2
3
4
5
6
7
        // clear the window with black colour
        window.clear(sf::Color::Black);

        window.draw(splash.sprite);

        // end the current frame
        window.display();





I need some kind of mind re awakening, I just need to pass a pointer, whys it so hard? I thought I would re-learn this in no time but nope.
Last edited on
XD TWO DAYS OF BEING STUPID AND I SUSS OUT I JUST DIDNT GIVE TEXTURE A SIZE RIGHT AFER POSTING!!!

K i just need to ask questions to clear my mind, issue solved thank you community for being here <3
Topic archived. No new replies allowed.