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

Author Topic: Handling loading of images  (Read 2767 times)

0 Members and 1 Guest are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Handling loading of images
« on: November 16, 2012, 09:40:27 pm »
In my crap game, my PrimaryMenu, SubMenus, CrapTable, Chips and Dice will all be PNG images.  I'm thinking that I should load all of the PNG images that I'll use in my program when the program is first opened.  No point in letting the user setup the game and then have the program try load the crap table image when the actual game is started, only to find out then that the crap table image on the hard drive is missing or corrupt.

Do you load all of your images when your program first starts?

If so, how do you store your images so they will be accessible to the different classes when they are needed?  I'm thinking about making a global struct to load all images into.  Is that a good way to do it, or is there a different recommended way?

Thanks,
Raptor


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Re: Handling loading of images
« Reply #1 on: November 16, 2012, 10:30:10 pm »
Do you load all of your images when your program first starts?
I load the resources when their needed, i.e. in the state that needs them.

If so, how do you store your images so they will be accessible to the different classes when they are needed?  I'm thinking about making a global struct to load all images into.  Is that a good way to do it, or is there a different recommended way?
I wouldn't to use any global variables.
If you're only conserne is the existance of some files, then you could simply do an integrity check at startup, i.e. check if every file exists or even better check if the checksum/md5sum match the original one. This method isn't recommended for big projects, because there would be many many files to check, which would take a while. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Handling loading of images
« Reply #2 on: November 17, 2012, 12:29:08 am »
Hi eXpl0it3r,

Thanks for your input.  Helps to get different points of view in how program a SFML game.

Raptor

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Handling loading of images
« Reply #3 on: November 17, 2012, 12:37:44 am »
Do you load all of your images when your program first starts?

Load the resources when you need them. There is a tutorial on the wiki that shows how to load files in a thread and display a progress bar.


...how do you store your images so they will be accessible to the different classes when they are needed?

Take a look at the image/texture managers on the wiki  ;)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Handling loading of images
« Reply #4 on: November 19, 2012, 09:49:10 am »
Thanks for your input mateandmetal.  Very interesting recommendations for further research.

Raptor