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

Author Topic: some day u´ll hate me =)  (Read 4213 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
some day u´ll hate me =)
« on: September 26, 2008, 07:50:42 pm »
so, why doesnt this code not work, i think about the movement - Input


Code: [Select]
int main()
{

// Create main window
    RenderWindow App;
    App.Create(sf::VideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,32), "SFML Window", Style::Fullscreen);
// Cursor is not being shown
    ShowCursor(0);
// create bats
    bat left;
    bat right;
    right.SetPosition(WINDOW_WIDTH - right.width,0);
//  INput
    const Input& Input = App.GetInput();
    bool left_up = Input.IsKeyDown(Key::W);
    bool left_down = Input.IsKeyDown(Key::S);
    bool right_up = Input.IsKeyDown(Key::Up);
    bool right_down = Input.IsKeyDown(Key::Down);


// Geschwindigkeiten

while (App.IsOpened())
{
    // Process events
    Event Event;
    while (App.GetEvent(Event))
    {
        // Close window : exit
        if (Event.Type == Event.Closed)
            App.Close();

        // keybord-events
        if ((Event.Type == Event.KeyPressed) && (Event.Key.Code == Key::Escape))
        {
            App.Close();
        }


    }

// handle bat-movements
    if( right_down)
    {
        right.Move(0, 400* App.GetFrameTime());
    }
    if(right_down)
    {
        right.Move(0, - 400 * App.GetFrameTime());
    }
    if(left_down)
    {
        left.Move(0, 400* App.GetFrameTime());
    }
    if(left_up)
    {
        left.Move(0, -400* App.GetFrameTime());
    }

// Draw left paddle;
    App.Draw(left);
    App.Draw(right);
// Finally, display the rendered frame on screen
    App.Display();

}


my bats dont move, when i write my input right above the if-clauses everything works fine, why?
does App.GetInput() needs to be refreshed every frame?

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
some day u´ll hate me =)
« Reply #1 on: September 26, 2008, 08:02:52 pm »
Your bats don't move because you're only checking input once at the beginning of the program.

All of this:

Code: [Select]
   const Input& Input = App.GetInput();
    bool left_up = Input.IsKeyDown(Key::W);
    bool left_down = Input.IsKeyDown(Key::S);
    bool right_up = Input.IsKeyDown(Key::Up);
    bool right_down = Input.IsKeyDown(Key::Down);


Needs to be put in your main loop somewhere. Also, you have right_down twice in your bat movement part of the loop.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: some day u´ll hate me =)
« Reply #2 on: September 26, 2008, 08:03:47 pm »
Quote from: "ravenheart"
so, why doesnt this code not work, i think about the movement - Input


I'm not sure, but just dividing by 0 or something should be a quick fix.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
some day u´ll hate me =)
« Reply #3 on: September 26, 2008, 08:04:56 pm »
Sorry...  :p  Ok, real answer:

Where you're setting the keypress bools is not in your main loop.  You need to move them there.  Think about how your program is flowing.  Also, did you try using the debugger?

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
some day u´ll hate me =)
« Reply #4 on: September 26, 2008, 08:17:25 pm »
ok i found it out by myself what i dont like is that i have to declare my bools every loop from new;

is there any possiblitiy to change that?

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
some day u´ll hate me =)
« Reply #5 on: September 26, 2008, 08:56:44 pm »
Declare them once at the beginning and then just re-assign them once each frame.