Java Game Programming #8 - Keyboard Input & Basic Collision

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

In this video we learn how to add basic keyboard input and collision. 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!

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

For everyone who is having trouble with the key not responding, make sure you spelled keyPressed with a small k not KeyPressed 

Linxy
Автор

To all the people whose playres are unresposive to the keyPressed method, the probem may be in the GameObject class. Make sure that the method setVelX take the variable Vel X: 
public void setVelX( float velX)


In addition, make sure that the tempObject in your Keyinput is identical to the tempObject in the Handler class. Meaning that if you initially type TEMPOBJECT in the Handler class you must put exactly the same TEMPOBJECT for the Keyinput.

iamabean
Автор

im an idiot, i spent 20 minutest trying to figure out why movement wasnt working whilte pressing arrow keys instead of A, D 

Wolloowizzard
Автор

in the GameObject (float x, float y, ObjectId id) { this.x = x; this.y = y; this.id = id <<< remember this }

joshuaupton
Автор

I can't get the middle and the sides of the walls. I can only get the bottom one.
Can you please tell me what I should do

codingisheaven
Автор

when/how did he make the blocks on the side/middle of the window?

tkaizer
Автор

I am taking my brain to platformer games and when you explained why my player gets stuck clearly I was like "wow my idea of resetting the players position once landed makes sense now" and then realized I'm not the only one that thought to do this 😁

droidlycodes
Автор

Hey I saw some other arrangement of blocks from the last tutorial when you first ran

arjavgarg
Автор

I've had trouble with this one. I know to request the focus in the init method, the only problem is when I request focus it doesn't do anything to it. No key presses work until I click off the window and back onto it. Not even system.out.println in the keyPressed works. Any tips? I've struggled too long with this.

LittleTas
Автор

2 years later but here is another fix. in the previous tutorial we disabled the x and y in PLayer (looks like //x =+ VelX) take away the comment marks (//) which then reactivates gravity, which worked for me

Shavinderyt
Автор

Bring them out faster realtuts
Thanks for the tutorial I've been waiting for it!

sufientout
Автор

Could anyone help with choppy movement? Seems as though I can't press 2 keys at once without it choking and stumbling. 

iJinXxedU
Автор

4:30 Just wondering: wouldn't it be lighter for the computer to put the "if(key == KeyEvent.VK_D" before browsing the whole list of GameObjects, then doing the same for the A key ?

matthieubatard
Автор

I had problem with moving objects and after few hours i find a mistake. My mistake was that i put diffrent name in GameObject in
 public  float setVelX( float velX){
return this.velX=velX;
}
public  float setVelY( float velY){
return this.velY=velY;
}

and in 
KeyInput class
if(key ==
if(key ==
Maybe someone have same problem u never know

StefanVelickovic
Автор

I love that dark theme.
Thank you so much for these tutorials, it has helped me so much! :D

jesusparra
Автор

These are so helpful, getting them faster would really be great

Wupdog
Автор

RealTutsGML, I am hooked on your game design. Please bring them out faster.

cbo
Автор

Instead of doing:
for(int i = 0; i < list.size(); i++)
{
Object tmp = list.get(i);
//code
}

You could do:
for(Object tmp : list)
{
//code
}

It does the same thing

megasalexander
Автор

I've read every comment and looked for every solution. Pressed key still does not result in movement of the player object. Thoughts?

narkjr
Автор

Please help i put code in from a comment to make walls and now my player shoots off the screen when i touch a wall so i read another comment that said how to fix that and that flips the whole screen on its sidePlease help

goldflow