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

Author Topic: Movement system does not work.  (Read 1847 times)

0 Members and 1 Guest are viewing this topic.

baguettio

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Movement system does not work.
« on: February 15, 2020, 04:17:16 pm »
Made a basic movement system from scratch using a switch rather than if statements, sprite is drawn but does not move.
   
 while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            // Checks the event
            switch (event.type){

                  // if you press close, close the window
                  case event.Closed: {
                          window.close();
                          break;}
                  case event.KeyPressed: {
                           switch (event.key.code){

                                   case Keyboard::A:{
                                        playerleft = true;
                                        break;}
                                   case Keyboard::D:{
                                        playerright = true;
                                        break;}

                                   default:
                                         break;    }
                                         }
                  case event.KeyReleased: {
                           switch (event.key.code){

                                   case Keyboard::A:{
                                        playerleft = false;
                                        break;}
                                   case Keyboard::D:{
                                        playerright = false;
                                        break;}
                                   default:
                                        break;   }
                  default:
                       break;

                                         }

                            } // closes the check event switch
       } // closes the event check loop




       Clock clock;
       float alphaTime = clock.restart().asSeconds();

       if (playerleft == true){
        xvel = -1;
       }
       if (playerright == true){
        xvel = 1;
       }
       if (xvel > 0){
        xvel =- 1*alphaTime;
       }
       if (xvel < 0){
        xvel =+ 1*alphaTime;
       }
       player.move(Vector2f(0.f+xvel,0.f+yvel));



        window.clear();
        window.draw(player);
        window.display();


    } // closes the window open loop
New to c++/sfml so sorry if this is a stupid question.
« Last Edit: February 17, 2020, 09:12:23 pm by eXpl0it3r »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Movement system does not work.
« Reply #1 on: February 15, 2020, 04:26:54 pm »
Don't forget any break, unless you know what you're doing.

baguettio

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Movement system does not work.
« Reply #2 on: February 15, 2020, 04:59:42 pm »
Oh right. I've fixed that, still does not work, however?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Movement system does not work.
« Reply #3 on: February 15, 2020, 08:53:44 pm »
Still missing break for case event.KeyPressed and case event.KeyReleased

 

anything