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

Author Topic: Insert images after App.Display();  (Read 2239 times)

0 Members and 1 Guest are viewing this topic.

pofro89

  • Newbie
  • *
  • Posts: 4
    • View Profile
Insert images after App.Display();
« on: January 01, 2012, 11:33:27 pm »
I don't know how to do :cry:

Code: [Select]
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
using namespace sf;
#include <iostream>
using namespace std;

 int main()
 {


     Image Image4,Image3,Image2,Image;
     // Create the main window
     RenderWindow App(VideoMode(800, 600), "Pofro Game");

     if (!Image.LoadFromFile("1.jpeg"))
         return EXIT_FAILURE;
     Sprite nav1(Image);

    nav1.SetPosition(30,20);

     if (!Image2.LoadFromFile("3.jpeg"))
         return EXIT_FAILURE;
     Sprite sfondo(Image2);


     if (!Image3.LoadFromFile("2.jpeg"))
         return EXIT_FAILURE;
     Sprite nav2(Image3);

     nav2.SetPosition(730,20);

     if (!Image4.LoadFromFile("4.jpeg"))
         return EXIT_FAILURE;
     Sprite miss(Image4);


     Font Arial;
     if (!Arial.LoadFromFile("verdana.ttf"))
         return EXIT_FAILURE;
     String Text("Hello SFML", Arial, 50);

     Music Music;
     if (!Music.OpenFromFile("nice_music.ogg"))
         return EXIT_FAILURE;

         Music.SetLoop(true);

     Music.Play();

    while (App.IsOpened())
     {

         Event Eventi;
         while (App.GetEvent(Eventi))
         {

             if (Eventi.Type == Event::Closed)
                 App.Close();

             if ((Eventi.Type == Event::KeyPressed) && (Eventi.Key.Code == Key::Escape))
             App.Close();

             if ((Eventi.Type == Event::KeyPressed) && (Eventi.Key.Code == Key::Space))
             App.Draw(miss);
                            }



float tempo = App.GetFrameTime();

        // Move the sprite
        if ((App.GetInput().IsKeyDown(Key::Left)) && (nav1.GetPosition().x>=2)) nav1.Move(-200 * tempo, 0);
        if ((App.GetInput().IsKeyDown(Key::Right)) && (nav1.GetPosition().x<=745)) nav1.Move( 200 * tempo, 0);
        if ((App.GetInput().IsKeyDown(Key::Up)) && (nav1.GetPosition().y>=2))   nav1.Move(0, -200 * tempo);
        if ((App.GetInput().IsKeyDown(Key::Down)) && (nav1.GetPosition().y<=556)) nav1.Move(0,  200 * tempo);


         App.Clear();

         App.Draw(sfondo);

         App.Draw(nav1);

         App.Draw(nav2);

         App.Display();
     }

     return EXIT_SUCCESS;
 }


doesn't work :cry:

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Insert images after App.Display();
« Reply #1 on: January 02, 2012, 03:10:35 am »
Please, explain yourself better. By the way, App.Clear(); should be right after the while. This way the "miss" sprite never gets displayed.

pofro89

  • Newbie
  • *
  • Posts: 4
    • View Profile
Insert images after App.Display();
« Reply #2 on: January 02, 2012, 11:10:18 am »
Code: [Select]
App.Clear();

App.Draw(sfondo);

App.Draw(nav1);

App.Draw(nav2);

App.Display();

App.Draw(miss);


It is possible?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Insert images after App.Display();
« Reply #3 on: January 02, 2012, 11:15:40 am »
No, why would you want to draw after everything has been displayed?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Insert images after App.Display();
« Reply #4 on: January 02, 2012, 11:15:59 am »
Of course not, because you'll clear the window after drawing the last sprite.

But why do you want to do that? It makes no sense.
Laurent Gomila - SFML developer

pofro89

  • Newbie
  • *
  • Posts: 4
    • View Profile
Insert images after App.Display();
« Reply #5 on: January 02, 2012, 11:45:54 am »
I want to make sure that when I press a button an object appears on the screen, but I do not want the object to be present when I app: display ()

Is there a way?

Neomex

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Insert images after App.Display();
« Reply #6 on: January 02, 2012, 12:29:39 pm »
It's hard to understand you, but as Tex killer said, you have to put App.Clear on the beggining of the loop, or right after App.Display. That's why you can't see 'miss' object when you press key.

App.Clear fill the whole screen with some color, so you won't see anything displayed before you called it.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
Insert images after App.Display();
« Reply #7 on: January 02, 2012, 01:09:56 pm »
Code: [Select]

bool show;

App.Clear();

if(sf::Keyboard::IsKeyPressed(sf::Keyboard::A))
{
    show = true;
}

if(show)
{
    App.Draw(sprite);
}

App.Display();



EDIT: If you want the object only to show up while the key is still down, get rid of the boolean and the second if statement then put "App.Draw(sprite);" in the first if statement.

pofro89

  • Newbie
  • *
  • Posts: 4
    • View Profile
Insert images after App.Display();
« Reply #8 on: January 02, 2012, 02:57:29 pm »
Thank's Pyrius :D