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

Author Topic: First Background image, then Foreground image  (Read 3189 times)

0 Members and 1 Guest are viewing this topic.

Construct

  • Newbie
  • *
  • Posts: 2
    • View Profile
First Background image, then Foreground image
« 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 :>

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
First Background image, then Foreground image
« Reply #1 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.
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
First Background image, then Foreground image
« Reply #2 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.

Construct

  • Newbie
  • *
  • Posts: 2
    • View Profile
First Background image, then Foreground image
« Reply #3 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).

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
First Background image, then Foreground image
« Reply #4 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.)
SFML / OS X developer