I guess putting random code wasn't doing what I wanted, well I was tired and couldn't think right but here anyways is my code:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
using namespace sf;
// Main
int main()
{
// Create the main window
RenderWindow app(VideoMode(256, 160), "game");
//Setting up variables for Title screen
Clock clock; // Clock variable for timers
Texture ScreenTexture;
Texture StartButtonTexture;
ScreenTexture.loadFromFile("TitleScreen.png");
StartButtonTexture.loadFromFile("GameStart.png");
Sprite TitleScreen(ScreenTexture);
IntRect GameStartRectangle(0,0,62,15);
Sprite GameStart(StartButtonTexture, GameStartRectangle);
GameStart.setPosition(97, 130);
Music TitleMusic;
TitleMusic.openFromFile("song.ogg");
TitleMusic.play();
// Start the Title screen loop
while (app.isOpen())
{
// Process events
Event event;
while (app.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
app.close();
}
// Animating the game start text in title screen
if (clock.getElapsedTime().asSeconds() > 0.35f)
{
if (GameStartRectangle.left == 62)
GameStartRectangle.left = 0;
else
GameStartRectangle.left += 62;
GameStart.setTextureRect(GameStartRectangle);
clock.restart();
}
// Drawing section //
// Clear screen
app.clear();
// Draw the sprite
app.draw(TitleScreen);
app.draw(GameStart);
// Update the window
app.display();
}
return 0;
}
Kinda nice code right, it shows a window, Title screen to be precise but I want to do this:
* Make a new class and store everything that's related to drawing the title screen and all animations.
* Render the window in main class and manage the other classes and states, also objects like player and enemies, while the new class just provides the resources like images and so on.
* When I press Return, I can change the titlescreen to game screen. (With screenfade in and out)
* Loading and unloading data when state is having some sort of event, for example the class that handles a game stage, when player dies, change the screen to new class and window state GameOver.