Hey
When i want build my code compiler shows the error:
Severity Code Description Project File Line Suppression State
Error C2871 'sf': a namespace with this name does not exist ConsoleApplication11 c:\users\kamil\documents\visual studio 2015\projects\consoleapplication11\consoleapplication11\game.cpp
Severity Code Description Project File Line Suppression State 9
ConsoleApplication11.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "stdafx.h"
#include "Game.h"
int main()
{
Game game;
game.runGame();
return EXIT_SUCCESS;
}
Game.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "Game.h"
#include "stdafx.h"
using namespace sf;
RenderWindow window(VideoMode(1280, 720), "Morbid Squirrel Wars");
Game::Game(void)
{
state = END;
if (!font.loadFromFile("Fonts/arial.ttf"))
{
//Error
}
state = MENU;
}
void Game::move()
{
if (state == GAME)
{
Texture tPlayer;
tPlayer.loadFromFile("Sprites/Player");
Sprite sPlayer;
sPlayer.setTexture(tPlayer);
}
}
void Game::runGame()
{
while (state != END)
{
switch (state)
{
case GameState::MENU:
menu();
break;
case GameState::GAME:
//
break;
}
}
}
void Game::menu()
{
Text Title;
Title.setStyle(Text::Bold);
Title.setFont(font);
Title.setCharacterSize(80);
Title.setString("Morbid Squirrel Wars");
Title.setPosition(1280 / 2 - Title.getGlobalBounds().width / 2, 20);
Text Play;
Play.setFont(font);
Play.setCharacterSize(65);
Play.setString("Play");
Play.setPosition(1280 / 2 - Play.getGlobalBounds().width / 2, 250);
Text Options;
Options.setFont(font);
Options.setCharacterSize(65);
Options.setString("Options");
Options.setPosition(1280 / 2 - Options.getGlobalBounds().width / 2, 370);
Text Exit;
Exit.setFont(font);
Exit.setCharacterSize(65);
Exit.setString("Exit");
Exit.setPosition(1280 / 2 - Exit.getGlobalBounds().width / 2, 490);
while (state == MENU)
{
Vector2f mouse(Mouse::getPosition(window));
Event event;
if (state == END)
{
window.close();
}
while (window.pollEvent(event))
{
//klikniêcie EXIT
if (Exit.getGlobalBounds().contains(mouse) &&
event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
{
state = END;
}
if (Play.getGlobalBounds().contains(mouse))
Play.setColor(Color::Cyan);
else Play.setColor(Color::White);
if (Options.getGlobalBounds().contains(mouse))
Options.setColor(Color::Cyan);
else Options.setColor(Color::White);
if (Exit.getGlobalBounds().contains(mouse))
Exit.setColor(Color::Cyan);
else Exit.setColor(Color::White);
}
if (Play.getGlobalBounds().contains(mouse) && event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
{
state = GAME;
}
window.clear();
window.draw(Title);
window.draw(Play);
window.draw(Options);
window.draw(Exit);
window.display();
}
}
Game::~Game()
{
}
Game.h
#pragma once
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "stdafx.h"
using namespace std;
using namespace sf;
class Game
{
public:
Game(void);
~Game(void);
void move();
void runGame();
enum GameState { MENU, GAME, GAME_OVER, END };
GameState state;
Font font;
void menu();
};