SFML community forums

Help => Graphics => Topic started by: Construct on November 12, 2009, 07:23:16 am

Title: First Background image, then Foreground image
Post by: Construct on November 12, 2009, 07:23:16 am
Hello there, i'm new to sfml :D
Is it possible to create a background image. Then display it and then display another image onto this?

for example:

I create the Background with 64x64 sprites(e.g. small grass sprites)...
Code: [Select]

//Inside game loop
for(int i=0;i <= 1024;i +=64)
{
for(int j=0;j <= 768;j +=64)
{
sprite.setPosition((float)i,(float)j);
app.draw(sprite);
}
}

This works fine, but when i got a map with a dimension of 36326346x35346346 Pixels (;D) this will cost a lot of time...so i want to create the background at first in a separate sprite/image, then create the foreground image and then display the stuff somehow...but i donno how to add "sprite" into another image/sprite with positioning.

Thought of something like this:
Code: [Select]

sf::Sprite tile;
//then loading the image etc...

sf::Sprite background;
for(...)
   background.Draw(tile,x,y);

//Same with foreground

//Mainloop here
app.Draw(background);
app.Draw(AllNPCsAndStuff);
app.Draw(foregound);


it's similar to the RPGMaker. Backgroundtiles first, then the NPCs and then the foreground tiles.

Hope somebody can help me :>
Title: First Background image, then Foreground image
Post by: Laurent on November 12, 2009, 08:51:13 am
This is not possible in SFML 1.5; SFML 2 provides some options to solve this kind of problems.
Title: First Background image, then Foreground image
Post by: Tank on November 12, 2009, 01:07:24 pm
Even in SFML2 it shouldn't be done like that!

Why don't you just render the stuff that's visible on the screen? There's no need to always draw the whole map.
Title: First Background image, then Foreground image
Post by: Construct on November 12, 2009, 03:19:32 pm
Hi there thanks for your answers :>

Quote
Why don't you just render the stuff that's visible on the screen? There's no need to always draw the whole map.


Mhh when it's not possible with sfml 1.5 (where to get 2.0 btw?) I think i should try that.

Ok then i need to think about it. I though I make a whol map image and when moving out of frame just setting the map's position to -X and -Y ( even though i wanted to draw stuff like dead people, blood, dirt etc.. This stuff would dissapear when moving out of screen and back. when i redraw all visible tiles every frame).
Title: First Background image, then Foreground image
Post by: Hiura on November 12, 2009, 05:48:02 pm
2.0 is under development and is available from the svn, in the branches directory. (See wiki/forum to know more about svn.)