1
Graphics / Insert images after App.Display();
« on: January 02, 2012, 02:57:29 pm »
Thank's Pyrius
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
App.Clear();
App.Draw(sfondo);
App.Draw(nav1);
App.Draw(nav2);
App.Display();
App.Draw(miss);
#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;
}