SFML community forums

Help => General => Topic started by: vorpal_sledge on February 08, 2014, 10:11:04 pm

Title: Arkanoid tutorial errors
Post by: vorpal_sledge on February 08, 2014, 10:11:04 pm
I recently decided to dive into game development using SFML, and thought that the Arkanoid clone tutorial would be a good place to start. However, I keep on getting errors in the code, and even downloading the source gives me these same errors.

The code as I have it is:

#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;
using namespace sf;

const int windowWidth{ 800 }, windowHeight{ 600 };

int main()
{
        RenderWindow window{ { windowWidth, windowHeight }, "Arkanoid - 1" };
        window.setFramerateLimit(60);

        while (true)
        {
                window.clear(Color::Black);

                if (Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;

                window.display();
        }

        return 0;
}

The errors I received from the VS2013 are :

I was able to fix the two errors for line sixteen (the const expr) by changing it to simply a const. I would like to know how to keep from having to do this, however.

Line 20 in my code (in case it doesn't show up) is the RenderWindow line, in case that helps.

Thank you!
Title: Re: Arkanoid tutorial errors
Post by: Hapax on February 08, 2014, 10:32:15 pm
Try creating the window using it's constructor rather than an initializer list.
This code is from the tutorial:
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
Title: Re: Arkanoid tutorial errors
Post by: vorpal_sledge on February 08, 2014, 10:57:20 pm
That works, as does simply replacing the windowWidth and windowHeight with 800 and 600 respectively in the original line. I still am not sure why using the const values causes an error on my machine, though.
Title: Re: Arkanoid tutorial errors
Post by: Hapax on February 09, 2014, 01:11:16 am
Have you tried using that line from the tutorial but used your constants for the dimensions? (i.e. use the constructor and use the sf::VideoMode part)
Title: Re: Arkanoid tutorial errors
Post by: vorpal_sledge on February 09, 2014, 01:44:44 am
Do you mean like this?

RenderWindow window{ VideoMode{ windowWidth, windowHeight }, "Arkanoid - 1" };

If so, yes, and it didn't work. It gave the same errors.
Title: Re: Arkanoid tutorial errors
Post by: Hapax on February 09, 2014, 02:45:20 am
No, no. I mean using the constructor (parentheses), not initializer lists (braces).
Does this work?
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Arkanoid - 1");
Title: Re: Arkanoid tutorial errors
Post by: vorpal_sledge on February 09, 2014, 02:52:53 am
Thank you! That made it work. Tutorial still confuses me, but as long as the code is working, I guess.
Title: Re: Arkanoid tutorial errors
Post by: Hapax on February 09, 2014, 03:05:30 am
I just played around with your constants/window creation code and it turns out that the only thing that you would need to change in it would be to make your constants the right type :p (i.e. unsigned int instead of int)
const unsigned int windowWidth{ 800 }, windowHeight{ 600 };

Also, you're welcome :)

EDIT:
This works too and looks tidier ;)
using namespace sf;
const VideoMode windowSize{ 800, 600 };
// ...
RenderWindow window{ windowSize, "Arkanoid - 1" };