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

Author Topic: Background image & Loading from resources  (Read 12653 times)

0 Members and 1 Guest are viewing this topic.

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Background image & Loading from resources
« on: July 26, 2009, 04:56:06 am »
I'm just starting with SFML, and so far it looks pretty easy and efficient.  But I have a couple of questions that are probably simple.

First, I saw the resource manager code in the wiki.  I saw its implementation for images and audio buffers.  My question is this.  Is this the code I should use if I want to put all of my images and audio files into a resource script to compile it all into my exe?  If not, what is the proper way to load images and sounds from a resource script?

Secondly, if I want to display a background image that is around 800x600, do I just use a large Sprite to do that?  Basically, is everything graphical that I draw just a sprite?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Background image & Loading from resources
« Reply #1 on: July 26, 2009, 02:27:04 pm »
Quote from: "forrestcupp"
Is this the code I should use if I want to put all of my images and audio files into a resource script to compile it all into my exe? If not, what is the proper way to load images and sounds from a resource script?
No, and that's rather not SFML's task. I think some IDEs support resources being compiled into the exe, but I am not sure because I haven't used this feature yet. Do you really need that, why don't you load resources at runtime?

Quote from: "forrestcupp"
Secondly, if I want to display a background image that is around 800x600, do I just use a large Sprite to do that?
Yes.

Quote from: "forrestcupp"
Basically, is everything graphical that I draw just a sprite?
No. For example, there are also displayed fonts (sf::String) or graphic primitives (sf::Shape). All the classes derived from sf::Drawable can be drawn. In the tutorials those things are explained further.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Background image & Loading from resources
« Reply #2 on: July 26, 2009, 08:07:32 pm »
Quote from: "Nexus"
No, and that's rather not SFML's task. I think some IDEs support resources being compiled into the exe, but I am not sure because I haven't used this feature yet. Do you really need that, why don't you load resources at runtime?
Well, I can load them at runtime if I have to.  One nice thing about loading from resources is that it eliminates one way for people who don't know what they're doing to screw things up.

In wxWidgets, there isn't direct support to load certain things from resources, but there are ways to do it with streams.  I was thinking that since SFML can load images and sounds from memory, maybe there's a way to do it from resources.  But if so, I can't really find any instructions on that.

But if there's no way around it, I'll just load the files at runtime.

Quote from: "Nexus"
No. For example, there are also displayed fonts (sf::String) or graphic primitives (sf::Shape). All the classes derived from sf::Drawable can be drawn. In the tutorials those things are explained further.
Right.  I wasn't really thinking of those when I said that.  I guess what I meant is that every preexisting image is going to be a sprite no matter what it's size and purpose is, right?

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Background image & Loading from resources
« Reply #3 on: July 26, 2009, 09:41:48 pm »
Quote from: "forrestcupp"
I was thinking that since SFML can load images and sounds from memory, maybe there's a way to do it from resources.  But if so, I can't really find any instructions on that.

But if there's no way around it, I'll just load the files at runtime.

If you wish to hide the files, you can make something like one files containing every resources. Okay the user could still delete it and prevent your application from running, but he would at least not be able to change your resources easily (that could even be made harder with encryption).
Want to play movies in your SFML application? Check out sfeMovie!

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Background image & Loading from resources
« Reply #4 on: July 26, 2009, 10:34:40 pm »
That would be cool if that's possible.  Do you know of any code examples of how to do that?  I don't have any idea how I could do that.  I can't even really find any examples of how to load things from memory.

I don't really care about encryption, though.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Background image & Loading from resources
« Reply #5 on: July 26, 2009, 11:21:16 pm »
I've never worked on something like this, but it doesn't seem too tricky to me.
You can do something like that in your "big" file :

In the first part you have : the size of the first part (in bytes), then the informations on each file (the offset of the resource in the file, the id of the resource).

Then in the second part : the data for each resource.
Want to play movies in your SFML application? Check out sfeMovie!

Jaenis

  • Newbie
  • *
  • Posts: 48
    • View Profile
Background image & Loading from resources
« Reply #6 on: July 27, 2009, 07:29:17 am »
I store files in a zip archive, it is quite simple to use.
Hmm, I could create wiki entry about this...

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Background image & Loading from resources
« Reply #7 on: July 27, 2009, 03:03:04 pm »
Interesting.  How do you extract the files from within SFML?

Another reason I want to hide my resources is so players can't just look at all of my graphics and know ahead of time what a level is going to be like.

klusark

  • Newbie
  • *
  • Posts: 45
    • View Profile
Background image & Loading from resources
« Reply #8 on: July 28, 2009, 12:44:58 am »
Quote from: "forrestcupp"
Interesting.  How do you extract the files from within SFML?

Another reason I want to hide my resources is so players can't just look at all of my graphics and know ahead of time what a level is going to be like.


Using zip files would not hide them from the user. I don't know why you would want to hide them, but you could make your own image format and put all your images in that format.

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Background image & Loading from resources
« Reply #9 on: July 28, 2009, 02:37:09 am »
Quote from: "forrestcupp"

Another reason I want to hide my resources is so players can't just look at all of my graphics and know ahead of time what a level is going to be like.

That's my main reason.  It shouldn't matter what my reasons are anyway.  It's a common practice to put graphics and sounds into a resource script.

If I create my own file extension, will SFML be able to read it?

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Background image & Loading from resources
« Reply #10 on: July 28, 2009, 03:54:51 am »
Because your using c++ you pretty much have unlimited capabilities to do what you want. Your own proprietary format of course wont be within SFML but you could program your own handler for it and have that work with SFML.
Eugene Alfonso
GTP | Twitter

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Background image & Loading from resources
« Reply #11 on: July 28, 2009, 02:44:29 pm »
SFML won't be able to read your custom formats directly. But you can convert them first to make them recognizable. If you perform the conversion (decryption) in RAM, you can use the SFML LoadFromMemory() functions.

However, that's pretty much effort...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Background image & Loading from resources
« Reply #12 on: July 28, 2009, 02:48:10 pm »
I think you should first focus an your program's main features and let this files' question for later.
Want to play movies in your SFML application? Check out sfeMovie!

4ian

  • Hero Member
  • *****
  • Posts: 680
    • View Profile
    • Game Develop website
Background image & Loading from resources
« Reply #13 on: July 28, 2009, 03:23:50 pm »
Instead of a zip file, which is easy to modify, you can use a DAT file. There is a tutorial on the french wiki : http://www.sfml-dev.org/wiki/fr/tutoriels/formatdat
( Even if it is in French, the comments are in English. )

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Background image & Loading from resources
« Reply #14 on: July 28, 2009, 08:55:01 pm »
Quote from: "4ian"
Instead of a zip file, which is easy to modify, you can use a DAT file. There is a tutorial on the french wiki : http://www.sfml-dev.org/wiki/fr/tutoriels/formatdat
( Even if it is in French, you the comments are in English. )

Sweet!  If I can't load from a resource script easily, that's definitely a good solution.  Thank you.

 

anything