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

Author Topic: Can you have two different global textures in different classes.  (Read 2686 times)

0 Members and 2 Guests are viewing this topic.

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
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.
« Last Edit: April 22, 2017, 03:52:04 am by Aerine »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can you have two different global textures in different classes.
« Reply #1 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?
Laurent Gomila - SFML developer

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can you have two different global textures in different classes.
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Can you have two different global textures in different classes.
« Reply #3 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 has an excellent resource holder class and the SFML Game Development book has some code for one as well.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Darkpony

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Can you have two different global textures in different classes.
« Reply #4 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 has an excellent resource holder class and the SFML Game Development 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)

« Last Edit: April 24, 2017, 02:28:04 am by Darkpony »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything