#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
int main()
{
std::cout << "This is the brain of the game, don't think of closing it\nPlease wait the game is loading . . . " << std::endl;
// declare mainWindow
sf::RenderWindow mainWindow( sf::VideoMode( 800, 600, 32) , "Hello title" , sf::Style::Close ); // Declare of mainWindow
std::cout << "Game resolution is : " << mainWindow.getSize().x << " X " << mainWindow.getSize().y
<< " bits : " << mainWindow.getSettings().depthBits + mainWindow.getSettings().stencilBits << std::endl;
// declared mainWidow
// load images into ram
sf::Image img_SpaceShip;
if( !img_SpaceShip.loadFromFile( "Resource/img_ship.png" ) )
std::cout << "Error LFF : Failed to load Resource/img_ship.png" << std::endl;
else std::cout << "Resource/img_ship.png successfully loaded" << std::endl;
sf::Texture img_button;
if ( !img_button.loadFromFile( "Resource/img_button.png" ) )
std::cout << "Error LFF : Failed to load Resource/img_button.png" << std::endl;
else std::cout << "Resource/img_button.png successfully loaded" << std::endl;
sf::Texture img_button2;
if ( !img_button2.loadFromFile( "Resource/img_button2.png" ) )
std::cout << "Error LFF : Failed to load Resource/img_button2.png" << std::endl;
else std::cout << "Resource/img_button2.png successfully loaded" << std::endl;
// load sound and music into ram
sf::Music msnd_intro;
if( !msnd_intro.openFromFile( "Resource/msnd_intro.ogg") )
std::cout << "Error OFF : Failed to load Resource/msnd_intro.ogg" << std::endl;
else std::cout << "Resource/msnd_intro.ogg successfully loaded" << std::endl;
msnd_intro.setLoop( true );
msnd_intro.play();
// loads fonts
sf::Font font_English;
if (!font_English.loadFromFile( "Resource/font_English.ttf" ) )
std::cout << "Error LFF : Failed to load Resource/font_English.ttf" << std::endl;
else std::cout << "Resource/font_English.ttf successfully loaded" << std::endl;
// every thing should be loaded
// declarations
sf::Text text_MainWindowText ( "SpaceShips 0.01 Alfa", font_English);
text_MainWindowText.setCharacterSize( 40 );
text_MainWindowText.setColor( sf::Color::Blue );
text_MainWindowText.setPosition( 200 , 30 );
sf::Text text_MainWindowNewGame ( "New Game", font_English);
text_MainWindowNewGame.setCharacterSize( 30 );
text_MainWindowNewGame.setColor( sf::Color::Green );
text_MainWindowNewGame.setPosition( 60 , 150 );
sf::Text text_MainWindowExit ( "Exit Game", font_English );
text_MainWindowExit.setCharacterSize( 30 );
text_MainWindowExit.setColor( sf::Color::Red );
text_MainWindowExit.setPosition( 60, 200 );
sf::Sprite spr_ButtonNewGame;
spr_ButtonNewGame.setTexture( img_button );
spr_ButtonNewGame.setPosition( 0 , 150 );
spr_ButtonNewGame.setScale( 1.8 , 1 );
sf::Sprite spr_buttonExitGame;
spr_ButtonNewGame.setTexture( img_button2 );
spr_ButtonNewGame.setPosition( 0 , 200 );
spr_ButtonNewGame.setScale( 1.8 , 1 );
// the main game loop
while ( mainWindow.isOpen() ) // main game loop
{
sf::Event mainEvents; // declare of main events checker
while ( mainWindow.pollEvent( mainEvents ) ); // checking
{
switch ( mainEvents.type ) // what event type
{
case sf::Event::EventType::Closed: // users clicks X or press Alt-F4
mainWindow.close(); // close the window
break;
}
}
// main loop :
mainWindow.clear( sf::Color( 11,11,11) );
mainWindow.draw( spr_ButtonNewGame );
mainWindow.draw( spr_buttonExitGame );
mainWindow.draw( text_MainWindowText );
mainWindow.draw( text_MainWindowNewGame );
mainWindow.draw( text_MainWindowExit );
mainWindow.display();
}
return EXIT_SUCCESS; // returns 0;
}
I tried making one texture for 2 sprites failed
then made 2 textures for 2 sprites failed
the problem is that it can only display one sprite at a time, I don't know why.
the difference from sf::Image and sf::Texture it says that that for memory and that for graphics card
so is it because I use sf::texture instead of sf::Image?
don't be hard on me, this is my first project
.