Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Arkanoid tutorial errors  (Read 3404 times)

0 Members and 3 Guests are viewing this topic.

vorpal_sledge

  • Newbie
  • *
  • Posts: 4
    • View Profile
Arkanoid tutorial errors
« 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 :
  • 1: Line 16 - int should be preceded by a ;
  • 2: Line 16 - missing type specifier, int assumed
  • 3: Line 20 - Element '1' - conversion from 'initializer-list' to 'sf::VideoMode' requires a narrowing conversion
  • 4: Line 20 - same, but from 'int' to 'unsigned int'
  • 5: Line 20 - same as 4, but applying to Element '2'

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!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Arkanoid tutorial errors
« Reply #1 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");
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

vorpal_sledge

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Arkanoid tutorial errors
« Reply #2 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Arkanoid tutorial errors
« Reply #3 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)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

vorpal_sledge

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Arkanoid tutorial errors
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Arkanoid tutorial errors
« Reply #5 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");
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

vorpal_sledge

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Arkanoid tutorial errors
« Reply #6 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Arkanoid tutorial errors
« Reply #7 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" };
« Last Edit: February 09, 2014, 03:09:58 am by Golden Eagle »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*