Quantcast
Channel: Question and Answer » game-loop
Viewing all articles
Browse latest Browse all 30

Movement in gameloop

$
0
0

I wonder what the best way is to move the player. Is it best to always check for movement like I do in the first example of is it better to only access the movement function via the input function like the 2nd example?


-EXAMPLE 1-
while(running)
{
    while(event)
    {
      player.input();
    }
    logic();
    render();
}
logic()
{
    player.move();
}


-EXAMPLE 2-
while(running)
{
    while(event)
    {
      player.input();
    }
    logic();
    render();
}
player.input()
{
    player.move(direction);
}
player.move(int dir)
{
    if(dir == left)
    {
        xvel += 1;
    }
}

I hope I explained it right. Thanks in advance.


Viewing all articles
Browse latest Browse all 30

Trending Articles