• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

question-closed Problem z kompilacja SFML

Object Storage Arubacloud
0 głosów
345 wizyt
pytanie zadane 18 marca 2017 w C i C++ przez QizmoPL Stary wyjadacz (11,440 p.)
zamknięte 20 marca 2017 przez QizmoPL

 

sf::Event eventCloseMainWindow;
		while (mainWindow.pollEvent (eventCloseMainWindow))
		{
			if (eventCloseMainWindow.type == sf::Event::Closed)
				mainWindow.close ();
		}

Severity    Code    Description    Line    File    Project    Suppression State
Error    C2027    use of undefined type 'sf::Event'    78    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2664    'bool sf::Window::pollEvent(sf::Event &)': cannot convert argument 1 from 'int' to 'sf::Event &'    76    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2065    'Closed': undeclared identifier    78    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2079    'eventCloseMainWindow' uses undefined class 'sf::Event'    75    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error (active)        incomplete type is not allowed    75    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error (active)        incomplete type is not allowed    78    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error (active)        incomplete type is not allowed    78    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error    C2228    left of '.type' must have class/struct/union    78    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
 

niewiem czemu nie chce sie skompilowac

komentarz zamknięcia: zmiana IDE pomogla, co bylo problemem nieiwiem
komentarz 18 marca 2017 przez BeSSeSSt Obywatel (1,190 p.)
Podesłany fragment służy tylko do zamknięcia okna. Podeślij cały szablon kodu.

ps. nie radzę nazywać zmiennych tak długimi nazwami
komentarz 18 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <random>
#include <string>
#include <chrono>
#include <thread>

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0

int randmoNumber (int intervalMin, int intervalMax);
void wait (unsigned int millisecondsTime);

int main (int argc, char * argv[])
{
	const int WIDTH = 700, HEIGHT = 400, DEPTH_OF_COLOR = 32, MAX_FPS = 60;
	const float PADDLE_WIDTH = 20, PADDLE_HEIGHT = 90;
	float ballSpeedX = 5.0, ballSpeedY = 0.0;
	const std::string SEPARATION = "|";
	int scorePlayerFirst = 0, scorePlayerSecond = 0;

	float ballRadius = 10.f;
	sf::Vector2f paddleSize (PADDLE_WIDTH, PADDLE_HEIGHT);

	//Load font
	sf::Font mainFont;
	if (!mainFont.loadFromFile ("resources/fontComic.ttf"))
		return EXIT_FAILURE;

	//Load music
	sf::Music mainMusic;
	if (!mainMusic.openFromFile ("resources/soundtrack.wav"))
		return EXIT_FAILURE;
	mainMusic.setLoop (true);
	mainMusic.setVolume (1);
	//mainMusic.play ();

	//Create the left paddle
	sf::RectangleShape leftPaddle;
	leftPaddle.setSize (paddleSize - sf::Vector2f (3, 3));
	leftPaddle.setOutlineThickness (3);
	leftPaddle.setOutlineColor (sf::Color::White);
	leftPaddle.setFillColor (sf::Color::Black);
	leftPaddle.setOrigin (paddleSize / 2.f);
	leftPaddle.setPosition (20, 200);

	//Create the right paddle
	sf::RectangleShape rightPaddle;
	rightPaddle.setSize (paddleSize - sf::Vector2f (3, 3));
	rightPaddle.setOutlineThickness (3);
	rightPaddle.setOutlineColor (sf::Color::White);
	rightPaddle.setFillColor (sf::Color::Black);
	rightPaddle.setOrigin (paddleSize / 2.f);
	rightPaddle.setPosition (680, 200);

	//Create the ball
	sf::CircleShape ball;
	ball.setRadius (ballRadius - 3);
	ball.setOutlineThickness (3);
	ball.setOutlineColor (sf::Color::White);
	ball.setFillColor (sf::Color::Black);
	ball.setOrigin (ballRadius / 2, ballRadius / 2);
	ball.setPosition (350, 200);



	//Main settings of windows
	sf::RenderWindow mainWindow (sf::VideoMode (WIDTH, HEIGHT, DEPTH_OF_COLOR), "PING-PONG", sf::Style::Titlebar | sf::Style::Close);
	mainWindow.setFramerateLimit (MAX_FPS);

	//Main loop game
	while (mainWindow.isOpen ())
	{
		sf::Event eventCloseMainWindow;
		while (mainWindow.pollEvent (eventCloseMainWindow))
		{
			if (eventCloseMainWindow.type == sf::Event::Closed)
				mainWindow.close ();
		}

		std::string scorePlayerFirstConversionToString = std::to_string (scorePlayerFirst);
		std::string scorePlayerSecondConversionToString = std::to_string (scorePlayerSecond);

		//Limit move right paddle
		if (rightPaddle.getPosition ().y < 0)
		{
			rightPaddle.setPosition (680, 0);
		}
		else if (rightPaddle.getPosition ().y > 400)
		{
			rightPaddle.setPosition (680, 400);
		}
		//Limit move left paddle
		if (leftPaddle.getPosition ().y < 0)
		{
			leftPaddle.setPosition (20, 0);
		}
		else if (leftPaddle.getPosition ().y > 400)
		{
			leftPaddle.setPosition (20, 400);
		}

		//Move left paddles
		if (sf::Keyboard::isKeyPressed (sf::Keyboard::W))
		{
			leftPaddle.move (0, -3);
		}
		else if (sf::Keyboard::isKeyPressed (sf::Keyboard::S))
		{
			leftPaddle.move (0, 3);
		}
		//Move right paddles
		if (sf::Keyboard::isKeyPressed (sf::Keyboard::Up))
		{
			rightPaddle.move (0, -3);
		}
		else if (sf::Keyboard::isKeyPressed (sf::Keyboard::Down))
		{
			rightPaddle.move (0, 3);
		}

		//Colision bounds
		sf::FloatRect leftPaddleCollision = leftPaddle.getGlobalBounds ();
		sf::FloatRect rightPaddleCollision = rightPaddle.getGlobalBounds ();
		sf::FloatRect ballCollision = ball.getGlobalBounds ();

		//TODO: Collision action
		ball.move (ballSpeedX, ballSpeedY);
		if (ballCollision.intersects (rightPaddleCollision))
		{
			ballSpeedX = -5;
			ballSpeedY = randmoNumber (0, 5);
			ball.move (ballSpeedX, ballSpeedY);
		}
		else if (ballCollision.intersects (leftPaddleCollision))
		{
			ballSpeedX = 5;
			ballSpeedY = randmoNumber (-5, 0);
			ball.move (ballSpeedX, ballSpeedY);
		}
		else if (ball.getPosition ().x > WIDTH)
		{
			scorePlayerFirst++;

			ball.setPosition (350, 200);
			rightPaddle.setPosition (680, 200);
			leftPaddle.setPosition (20, 200);
			ballSpeedX = 5.0;
			ballSpeedY = 0.0;
			ball.move (ballSpeedX, ballSpeedY);
			wait (500);
		}
		else if (ball.getPosition ().x < 0)
		{
			scorePlayerSecond++;
			ball.setPosition (350, 200);
			rightPaddle.setPosition (680, 200);
			leftPaddle.setPosition (20, 200);
			ballSpeedX = 5.0;
			ballSpeedY = 0.0;
			ball.move (ballSpeedX, ballSpeedY);
			wait (500);
		}
		else if (ball.getPosition ().y > (HEIGHT - 5))
		{
			ballSpeedX = -5;
			ballSpeedY = randmoNumber (-5, 5);
			if (ballSpeedY == -1 || ballSpeedY == 0 || ballSpeedY == 1)
				ballSpeedY = randmoNumber (-5, 5);
			ball.move (ballSpeedX, ballSpeedY);
		}
		else if (ball.getPosition ().y < 5)
		{
			ballSpeedX = 5;
			ballSpeedY = randmoNumber (-5, 5);
			if (ballSpeedY == -1 || ballSpeedY == 0 || ballSpeedY == 1)
				ballSpeedY = randmoNumber (-5, 5);
			ball.move (ballSpeedX, ballSpeedY);
		}

		std::string scoreGame = scorePlayerFirstConversionToString + SEPARATION + scorePlayerSecondConversionToString;

		//Score
		sf::Text scoreText (scoreGame, mainFont);
		scoreText.setCharacterSize (30);
		scoreText.setStyle (sf::Text::Bold);
		scoreText.setPosition (325, 10);

		mainWindow.clear (sf::Color::Black);
		mainWindow.draw (scoreText);
		mainWindow.draw (leftPaddle);
		mainWindow.draw (rightPaddle);
		mainWindow.draw (ball);
		mainWindow.display ();
	}

	return 0;
}

void wait (unsigned int millisecondsTime)
{
	std::this_thread::sleep_for (std::chrono::milliseconds (millisecondsTime));
}


int randmoNumber (int intervalMin, int intervalMax)
{
	std::random_device random;
	std::mt19937 gen (random ());
	std::uniform_int<> randomNumber (intervalMin, intervalMax);
	return randomNumber (gen);
}
2
komentarz 18 marca 2017 przez Ehlert Ekspert (212,670 p.)

ps. nie radzę nazywać zmiennych tak długimi nazwami

Totalna bzdura. Nazwa jest bardzo dobra. Czytasz i od razu wiesz z czym masz do czynienia. Plus dla autora za nazewnictwo. 

komentarz 18 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
Stworzenie nowego projektu ni nie pomaga

2 odpowiedzi

0 głosów
odpowiedź 18 marca 2017 przez Munvik Dyskutant (9,350 p.)
Jak linkujesz ? Includujesz <SFML...> ?
komentarz 18 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
komentarz 18 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
A biblioteke wrzucam do folderu
0 głosów
odpowiedź 19 marca 2017 przez Ehlert Ekspert (212,670 p.)
Z jakiego IDE korzystasz? Zrobiłeś coś oprócz wrzucenia biblioteki do folderu i dopisania include'ów do kodu?
komentarz 19 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
chodzi o to, ze wczesniej dzialalo, korzystam z VS15 robilem wszystko zgodnie z poradnikiem na stronie SFML
komentarz 19 marca 2017 przez Ehlert Ekspert (212,670 p.)
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

Wrzuć ten kod i sprawdź czy się kompiluje. 

komentarz 19 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
Severity    Code    Description    Line    File    Project    Suppression State
Error    C2664    'bool sf::Window::pollEvent(sf::Event &)': cannot convert argument 1 from 'int' to 'sf::Event &'    13    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2027    use of undefined type 'sf::Event'    15    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2228    left of '.type' must have class/struct/union    15    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error (active)        incomplete type is not allowed    12    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error (active)        incomplete type is not allowed    15    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error (active)        incomplete type is not allowed    15    c:\Users\Matusz\Documents\Visual Studio 2015\Projects\SFML\SFML\main.cpp    SFML    
Error    C2079    'event' uses undefined class 'sf::Event'    12    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Error    C2065    'Closed': undeclared identifier    15    c:\users\matusz\documents\visual studio 2015\projects\sfml\sfml\main.cpp    SFML    
Lista blędow
komentarz 19 marca 2017 przez QizmoPL Stary wyjadacz (11,440 p.)
Szukałem na anglojęzycznych forach i nic nie ma

Podobne pytania

0 głosów
1 odpowiedź 811 wizyt
pytanie zadane 18 września 2017 w C i C++ przez 10kw10 Pasjonat (22,880 p.)
+1 głos
4 odpowiedzi 700 wizyt
pytanie zadane 28 sierpnia 2016 w C i C++ przez easytodo Mądrala (5,380 p.)
+1 głos
1 odpowiedź 436 wizyt
pytanie zadane 29 marca 2016 w C i C++ przez Lee Nowicjusz (180 p.)

92,555 zapytań

141,403 odpowiedzi

319,559 komentarzy

61,940 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...