0
\$\begingroup\$

I use the following methods and the screen moves away from the player.

glTranslatef(h.x - width/2, h.y - hieght/2, 0);


        if ((Keyboard.isKeyDown(Keyboard.KEY_D))) {

            h.x += 10;
        }

        if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
            h.x -= -10;         
        }

How do I make it so the player and the screen moves? Also shouldn't I just use the camera?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Your keyboard events should move the player. And the camera should follow the player. That seems the most logic, you have a moving object and you track it with the camera.

They are trying to do a similar thing here.

I don't know how you move your player, but your code would look something like that

if (Keyboard.isKeyDown(Keyboard.KEY_D))
{
    //Move player to the right
    player.x += 10;
}

if (Keyboard.isKeyDown(Keyboard.KEY_A)) 
{
     //Move player to the left
    player.x -=10;
}

glTranslate2f(-player.x,-player.y,0);

This is just to give you an idea, this can't be used as is. You have to adapt it to your needs.

\$\endgroup\$
1
  • \$\begingroup\$ perfect, not too smooth but great! \$\endgroup\$ May 15, 2014 at 0:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .