Java Game Programming #10 - Camera Class

preview_player
Показать описание

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 fun learning!

Рекомендации по теме
Комментарии
Автор

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.

PrGamingInk
Автор

I noticed that if you bind to "up arrow" also the jump function and you try to jump while moving, the player stops moving when it reaches the ground after falling, even if you keep golding down the left/right arrow keys - I think there might be some issues with JVM simultaneous key events, but I think I found a workaround.
Simply tweek your input functions this way:
   -  on key pressed, put the key code in a "key codes" array registering only the key code values;
  - on key released, remove the key code from the array;
  - in the tick function, if the Object is the Player and if the right arrow code is still IN the key codes array, right movement will be performed (so simply check if the key code is in the array), as well as the left movement function for the left arrow key.

Hope this helps you a bit
Sergio

redsanso
Автор

Tip for eclipse users. Hold alt+shift + s and than select generate getters and setters. Makes life easier.

mikolec
Автор

i think youtube removed annotations does anyone have the link to the gamemaker video???

morganb
Автор

if you want the smooth camera:
float xTarg = -player.getX() + Game.WIDTH/2;

x += (xTarg - x) * (Number between 0 and 1)

chri
Автор

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?

jamilu
Автор

awesome, how would you snap the camera though? so it wont show outside the borders of the level?

Ozterkvlt
Автор

I did everything that you did in your video but i added to have the camera some movements to go up and down, but the camera shakes a lot, i tried to figuring it out, i even check to see if it was the collision of the player and the floor, so what do i do?

MichaelFlares
Автор

The translate method in Graphics2D solves an issue I've been having for a couple of days - thanks.

renbinden
Автор

when you go for android game series?Thanks

StefanBanu
Автор

I have a problem with my g2d.translate. The error says "The method translate(int, int) in the type Graphics is not applicable for the arguments (float, float)". Please help! :(

OfficialGamingNetwork
Автор

How do you do if you want a HUGE level? I guess you will only tick and render the ones close to the camera, but... how do you do that? ;)








I've been trying for so long

freerangerstudios
Автор

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

galaxybox
Автор

Another way to smooth camera moving in y is to change the variables from float to int, otherwise there will be a shake effect.

freerangerstudios
Автор

I can't get the x = player.getX() + Game.WIDTH/2; to work and I used to see what my width was and it says my width is 1 any reason why that would be and how to fix it? I tried also just putting in the number (x = 400) but I get weird results.

Funske
Автор

Just came across these tutorials and they're great.  Watched them all today and want more.  

westr
Автор

Why not just use instanceof when checking for Player?

MasterFragger
Автор

Hey, I didnt understand how the translate command works, can you explain it more deeply?

guyshuster
Автор

How do you get the camera to stop at x=0, x=the width of the game, and the same for y, so that you can't see beyond the stage?

XenkoVence
Автор

can we add a actual rear camera view as game background ? i coudnt solve it ..please help

yasif