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

Author Topic: Im stuck with tutor. #1  (Read 2105 times)

0 Members and 1 Guest are viewing this topic.

Ilya83

  • Newbie
  • *
  • Posts: 5
    • View Profile
Im stuck with tutor. #1
« on: January 06, 2014, 11:23:51 pm »
Im new in SFML and Im new in C++ too And I don't even speak engl. (OMG What am I doing in here  :o) Just want to do the video tutor 1 But seems Im stuck. I can't use the "constexpr" So I decided to use just CONST And I got the problem witch i can't solve The problem is "Vector2f velocity". Any help please  :) 
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;
using namespace sf;

const unsigned WINDOW_WIDTH = 800;
const unsigned WINDOW_HEIGHT = 600;
const float BALL_RADIUS = 10.f;
const float BALL_VELOCITY = 8.f;

struct Ball
{
    CircleShape shape;

    Vector2f velocity(-BALL_VELOCITY, -BALL_VELOCITY);

    Ball(float mX, float mY)
    {
        shape.setPosition(mX, mY);
        shape.setRadius(BALL_RADIUS);
        shape.setFillColor(Color::Red);
        shape.setOrigin(BALL_RADIUS, BALL_RADIUS);
    }

    void update(){shape.move(velocity);}
};

int main()
{
    Ball ball(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);

    RenderWindow window(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Arkanoid-1");
    window.setFramerateLimit(60);

    while(true)
    {
        Event event;
        window.pollEvent(event);

        window.clear(Color::Black);

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

        ball.update();
        window.draw(ball.shape);
        window.display();
    }

    return 0;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10901
    • View Profile
    • development blog
    • Email
Re: Im stuck with tutor. #1
« Reply #1 on: January 06, 2014, 11:43:48 pm »
Well can you describe what the problem actually is? Like compiler error? Runtime error?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ilya83

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Im stuck with tutor. #1
« Reply #2 on: January 06, 2014, 11:49:46 pm »
My problem is

const float BALL_VELOCITY = 8.F;
Vector2f velocity(-BALL_VELOCITY,-BALL_VELOCITY);
The compil says : expected identifier before '-' token

If I delet '-' Comp. says : BALL_VELOCITY is not a type
(os windows, qt creator(gcc))

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: Im stuck with tutor. #1
« Reply #3 on: January 07, 2014, 05:46:38 am »
because BALL_VELOCITY is a variable not a type
and you must not plase a - character before it
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10901
    • View Profile
    • development blog
    • Email
AW: Im stuck with tutor. #1
« Reply #4 on: January 07, 2014, 07:54:25 am »
That's not the problem here, instead it's because his compiler doesn't support C++11, thus he can't init member variables a declaration.
Instead I suggest to add a simple constructor that inits the variable in the initialization list. ;)

Also I highly recommend to get a C++11 compiler. The video tutorials make heavy use of new features, it will be quite hard to follow them without C++11.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ilya83

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Im stuck with tutor. #1
« Reply #5 on: January 07, 2014, 08:22:41 am »
added the QMAKE_CXXFLAGS += -std=c++11 in my .pro file And now I'm using C++11 The problem solved Thanks everyone  :D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10901
    • View Profile
    • development blog
    • Email
Re: Im stuck with tutor. #1
« Reply #6 on: January 07, 2014, 09:00:23 am »
Ah you didn't have it activated! :D

Now you might also be able to use constexpr.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ilya83

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Im stuck with tutor. #1
« Reply #7 on: January 07, 2014, 12:40:10 pm »
I'm using it right away!  :D But didn't find anything about constexpr  :(  Now I'm trying to figure out why he use the brace in setSize func and doesn't use it in setOrigin func  :o

 shape.setSize({paddleWidth, paddleHeight});

 shape.setOrigin(paddleWidth / 2.f, paddleHeight /2.f);
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10901
    • View Profile
    • development blog
    • Email
Re: Im stuck with tutor. #1
« Reply #8 on: January 07, 2014, 01:22:41 pm »
That's essentially a question for Laurent, why do so function have an overload for (float, float) while others have just the (sf::Vector2f)? (I bet there have been a few posts about this already...)

Given that I haven't watched the video and thus don't know if he has actually said something about it, I simply assume, that he used the uniform initialization (curly brackets) for the setSize function, because it only accepts an sf::Vector2f, which will get created on the fly with those brackets and you don't have to type the full class name. For the setOrigin function he uses the "native" overload of (float, float), because it's there.
Some might argue about not having to construct a temporary sf::Vector2f object, but that really doesn't matter. Much more interesting would be a discussion about consistency, like when should one use the overloads (if existing) and when should one use the vector directly.

In any case the width and height, could've also been packaged into a sf::Vector2f in the first place, making the code more compact, but maybe introducing more challenge for teaching the code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ilya83

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Im stuck with tutor. #1
« Reply #9 on: January 07, 2014, 02:44:33 pm »
silly me shape.setSize({paddleWidth, paddleHeight}); has curly brackets cos setSize has only 1 parameter !  :P

 

anything