Java Game Programming #10 – Camera Class

Produce your own Java game from scratch with this very simple, yet very powerful course available right now

In this video we add the camera class into our game. Now we can roam around the level all we want. If you have any questions then be sure to leave a comment or contact me on twitter; realtutsgml. If you learned something then be sure to leave a like, comment, and favorite.

Have you ever wanted to create games? Have you ever gotten fed up with it being to difficult? Well now is the time to thank me and possibly subscribe because you have just found the channel for you! Game Maker Tutorials, Java Game Programming, Unity3D Tutorials, Batch, C++ and much much more! This is the channel for you, the one stop shop for an exploration of your hidden talent as a game developer. Unleash your potential and go wild with imagination when you finally figure out how to make any game you want!

Visit CodingMadeSimple for more exclusive tutorials and get the help you need to succeed as your very own indie game developer!

Follow me on twitter for exclusive content and interaction with me!

Game Maker Studio: Programming
Game Maker Studio: Tutorial
Java Programming
Game Programming
Game Tutorial
Programming Tutorial


28 thoughts on “Java Game Programming #10 – Camera Class”

  1. Last video you said to show smooth movement in this case. When a "movement button" is pressed really fast. It stops moving, and then continues just as thinking a while. But I never saw you to show, Please can you show it?

  2. Wouldn't it be better to pass the camera instance to the handler's tick method and check if the object is a player in the loop that ticks all the objects?

    Also, I think it's "tweening", not tweAning 😉

  3. Could anyone help me for some reason my camera goes way faster than my player and the left side it kinda glitches out and when i move right the blocks start glitching out and my player just glitches and the player falls right through the block leaving a blue trail if you want i could send you my code

  4. You should be writing the minus marks in Class Game render() -method this way:

    g2d.translate(-camera.getX(), -camera.getY()); //begin of camera
    g2d.translate(camera.getX(), camera.getY()); //end of camera


    g2d.translate(camera.getX(), camera.getY()); //begin of camera
    g2d.translate(-camera.getX(), -camera.getY()); //end of camera

    it's then easier to control the camera's tick() -method: 
    x = player.getX() – Game.WIDTH/2;

  5. For everyone whos camera is way faster than the player make sure u delete the line in ur "game" class.
    g2d.translate(cam.getX(), cam.getY()); <———— DELETE THIS!!!!!!!!!

     //DRAW HERE

    g.fillRect(0, 0, getWidth(), getHeight());

    g2d.translate(cam.getX(), cam.getY()); //begin of cam


    g2d.translate(cam.getX(), cam.getY()); // end of cam

  6. I added y = -player.getY() + Game.HEIGHT/2; to the tick method in camera to have the player always centered on the screen and you can see more things above the player when you jump

  7. In the previous video you said you would explain how to fix the sticky key problem of the character sometimes stopping moving.

    Could you explain this please?

  8. Why some time you added or removed some code before you start your lecture ? It make me confuse somtime why don't you doing this job during you lecture so that we can easilly to follow ? btw could we have some code of all the lecture pls?

  9. I think it'd be more efficient if the player was not in the handler's list of objects and was rendered separately.

  10. Guys: If you wanna have a Y coord in the camera class, change the x and y variables to int and just cast for the player coords. If you use floating point integers (float) for the Y coordinates, it'll start shaking and being wonky.

  11. my camera is inverted. pls help

    nevermind i fix it. i forget the "-" on the "player".

    my mistake was: x = player.getX() + Game.WIDTH/2;

    and i fix it to: x = -player.getX() + Game.WIDTH/2;

Leave a Reply