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

Author Topic: [SOLVED] Loading textures multiple times  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

Stone

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] Loading textures multiple times
« on: May 28, 2017, 01:51:03 am »
Hi,

I tried to find my answer through search but can't find exactly what I'm after just yet.
I'm wondering if sfml will load a texture multiple times if I have multiple different object instances that call the load function, asking for the same texture? Or will it detect that it has already been loaded and use the same texture? If not, then I assume loading the same texture multiple times is not the most optimal solution.

Given this scenario, would it be a good idea to create a sprite manager class, load all textures I need on game start, encapsulate them in sprites, store them, and then assign them to these object instances?

Thanks in advance.
« Last Edit: May 28, 2017, 02:12:41 am by Stone »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Loading textures multiple times
« Reply #1 on: May 28, 2017, 02:08:23 am »
If you ask the a file to be loaded and stored, it will be loaded and stored regardless of whether or not that file has been loaded and stored already.

If you wish to re-use resources such as textures, you can use some form of resource manager and make that accessible to all functions and objects that need them. However, for simple applications with a single resource, for example, you can load the file once and then pass a reference (or pointer) to that texture around to your functions.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Stone

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: [SOLVED] Loading textures multiple times
« Reply #2 on: May 28, 2017, 02:13:17 am »
That's the confirmation I needed.

Thanks for the quick answer :D

 

anything