SFML community forums

Help => Graphics => Topic started by: Aerine on April 22, 2017, 03:49:18 am

Title: Can you have two different global textures in different classes.
Post by: Aerine on April 22, 2017, 03:49:18 am
I know the best thing to do is create a resource manager, and when i get there i get there. But my question is if i have a sf::Texture X declared globally in one cpp and assigned to a sprite in that cpp.  Can i have sf::Texture Y declared globally in another cpp and assigned to a sprite in that cpp. It keeps telling me that texture is already defined.
Title: Re: Can you have two different global textures in different classes.
Post by: Laurent on April 22, 2017, 09:33:15 am
You should not have to declare global variables, and especially not sf::Texture. Why do you do that?
Title: Re: Can you have two different global textures in different classes.
Post by: Aerine on April 22, 2017, 07:35:25 pm
I just wanna see my textures while i'm making my game instead of white boxes. Then when the game is finished ill make a resource management class
Title: Re: Can you have two different global textures in different classes.
Post by: eXpl0it3r on April 22, 2017, 07:50:04 pm
Make a resource holder class now. Global SFML resources will more often than not lead to crashes due to undefined destruction order.

Thor (http://www.bromeon.ch/libraries/thor/tutorials/v2.0/resources.html) has an excellent resource holder class and the SFML Game Development (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources) book has some code for one as well.
Title: Re: Can you have two different global textures in different classes.
Post by: Darkpony on April 24, 2017, 02:22:58 am
Make a resource holder class now. Global SFML resources will more often than not lead to crashes due to undefined destruction order.

Thor (http://www.bromeon.ch/libraries/thor/tutorials/v2.0/resources.html) has an excellent resource holder class and the SFML Game Development (https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources) book has some code for one as well.

what would a function in main that uses the Game Development example look like. Would it look something like this?

ResourceHolder exampleTexture;

sf::Texture cake;

exampleTexutre.load(cake, directory)

Title: Re: Can you have two different global textures in different classes.
Post by: Hapax on April 24, 2017, 12:27:23 pm
what would a function in main that uses the Game Development example look like
https://github.com/SFML/SFML-Game-Development-Book/blob/7dc99a87295922aa28c0a09ec7c4a8989818745e/02_Resources/Source/Main.cpp#L24-L34