Hey Guys! Welcome back. The last episode wasn´t my best work. Felt like the overall quality was not very high. But, i try to improve and i hope this one can make up for it. The intro is stupid i know, but i loved it, had to keep it xD Enjoy!
I like your videos so much. They help me a lot that now I can understand the basic concepts behind the sense. It would be extremely good if you can sometimes resonate why choosing something to handle is the best fit in situations. Thank you and hope for your new videos :)
When we switch the animation, its better to reset the animationIndex back to 0, otherwise it causes the image to flicker. For example the running animation has 6 frames and suppose we are moving, and stopped when the running animation was at 6th frame. The playerAction will instantly change to IDLE but what about the animationIndex? This will cause a blank subImage to be rendered. Here is my approach for fixing it: private void setAnimation() { if (moving) { if (playerAction == IDLE) { animationIdex = 0; playerAction = RUNNING; } } else { if (playerAction == RUNNING) { animationIdex = 0; playerAction = IDLE; } } }
case RUNNING: return 6; case IDLE: return 5; case HIT return 4; case JUMP: case ATTACK_1: case ATTACK_JUMP_1: case ATTACK_JUMP_2: return 3; case GROUND: return 2; case FALLING: default: return 1; i got you bro❤
package utils; public class Constants { public static class PlayerConstants{ public static final int RUNNING = 0; public static final int IDLE = 1; public static final int JUMP = 2; public static final int FALLING = 3; public static final int GROUND = 4; public static final int HIT = 5; public static final int ATTACK_1 = 6; public static final int ATTACK_JUMP_1 = 7; public static final int ATTACK_JUMP_2 = 8; public static int GetSpriteAmount(int player_action) { switch(player_action) { case RUNNING: return 6; case IDLE: return 5; case HIT: return 4; case JUMP: case ATTACK_1: case ATTACK_JUMP_1: case ATTACK_JUMP_2: return 3; case GROUND: return 2; case FALLING: default: return 1; } } } }
Hello, I really like this tutorial series. I am a Java developer for many years now but I never did any gaming/advance UI stuff and I really like you content! Please note that you have something of a bug, meaning the paintComponent() method should have requestFocus(true); in it, or else on my local machine it would lose focus about 1/4 of the times. Also consider adding private constructors to your constant classes :)
this channel is something else man, thank you for all of this great things Jesus, can believe I found you, how should I practice all of these for being good as you are? :D
hello @KaarinGaming , at 4:18 seconds , how did u get the x,y,width, height as i. we have declare a variable right and initialize . if i do that then the in the for loop it shows error and asks me to rename the the i in for loop . please help at the earliest
Hey @KaarinGaming, your tutorials are amazing, but I have an issue when it comes to adding animations. When I try to run the program (at around 11:27), I get an exception -> Exception in thread "main" java.awt.image.RasterFormatException: (x + width) is outside of Raster. How can I resolve this? Thank you in advance.
Hey@@KaarinGaming, thank you so much for the reply! I finally got it to work, I reversed the dimension values by mistake and thus granted exceptions in my code. Thank you so much once again for your help.
Excellently helpful and extremely well structured course! But, where did you get that set of images? Did you draw it anyway or collected from any web source? After finishing this course I have planned to clone one of my favorite childhood games, which names 'Shark Attack'.. so I was wondering if I could get any website on the internet which provides some tool to create this kind of images with which we can create any (if not 3D, then 2D) animations we want. Can you tell me about any resource like that?
I saw they sell games.. I wanted a tool to build up animations as game engines like Unity are too heavy for my computer.. Anyway, how about you make a tutorial on creating 2D models in a game engine and show how to integrate those models with our java code?
hey there, I think you might have written....'key pressed' contents into 'key released '. I had same bug. Ugh actually , my dumbself caused it but, hey I solved it too! so it's okay!🥲...so it could be the same case to yours. Hope it helps!
I'm getting an error at the switch inside the updatePos() function, it just says "duplicate case". I don't know why. Also, why you have Game class imported inside KeyboardInputs? If I do Import, I get the yellow mark saying it's not being used for anything but yours don't. Edit: I figure, I forgot to set the up, right, down constants to 1, 2 and 3 respectively. They were all with value 0... oh well, moving on.
Thanks for your video. It's very great. but i have a question.I have idle animations divided from 1 to 25. How can I merge them into one image like player_sprites.png?
I'm running into a problem where if I release the key at the end of the player's animation, they flicker as if their last image is blank, but when I hold the key, the animation plays without flickering.
I have a problem where the sprite doesn't move, it plays the animation but it just doesn't work EDIT: nvm, in the setDirection method instead of updating the playerDirection i instead updated the player action, mb.
You need to consider the size of each sprite, amounts of animations and the amount of sprites per animation. Worth mentioning that collisions only work (in this code) for hitboxes smaller than a tile. Good luck
Hi! How did you save the icon image for a player on each row and column? On my PC, the image is moving on the left and right side and is not in the same place to see just the character moving
I've noticed a problem. When I try to move my sprite with keyboard ( I removed mouse controls 'caouse I don't want'em ), I have to do it immediately after my game launches, becaouse when I do it like a second after it launches, it won't do anything, at least I won't see it maybe it moves but repaint does not work?
Sometimes I play the program and it works. Then, without changin a thing, I play the program again and it doesn't get the keyboard inputs... can someone help me with that?
Hello, great video, but I have a little problem: For some reason, my game speeds up after a certain time. I also noticed that my animation and moving speed are slower than yours. Then, after running the program for a few minutes, the game speeds up, and everything becomes faster. Can anyone help? edit: It also seems that the movement is not smooth. In an earlier video, you said that this is caused by the repaint() loop and that the thread loop would fix this problem. But it seems that I still have this problem.
Hey. Does not sound like its working correct. Make sure to take a look at github for code and then there is always a discord server to check out for more help. Usually its some small bit missing in your code. :)
@@KaarinGaming Hey thanks for the quick response. I compared my code to the one on github but everything looked fine. Maybe it has something to do with my PC, maybe it's just processing it slower first and then catches up. In Unity Time.deltaTime is used for the speed of movements, to maintain a consistent speed, regardless of the system the game is played. Do you implement something similar later in the tutorials?
Np. The game is far to simple as of now to make the game lagg or so. Could just be the same issue I faced while developing. Long story short, it goes to fast. So it laggs. When we add the level it went away. It was a linux thing for me. Regarding the delta you speak of, something similar is added. We don't use delta time, but we do store past time to make sure the game can "catch up". It comes in ep 7 or so when we fix the game loop.
@@KaarinGaming Ok. I have continued with the tutorials and after implementing Loop 2.0 the problem now apparently has gone away. Thanks again for the response.
Hello, at this point my game is already laggy, especially when I move the playe with the keyboard. I've 100% of CPU usage in one of the threads. I have played Red Dead Redemption 2 on this PC so I think it should be able to handle this game. Any ideas? EDIT: I noticed that even when I'm not pressing any keys one CPU core goes up to 100% usage, so probably not a Keyboard Input problem. EDIT: The game is working fine in Windows but not in Ubuntu, maybe a JVM problem?
Hey. This will go away. ( if it is what I am thinking of) It's a thing with Ubuntu/linux. It goes to fast in simple words. If you were to create a 100x100 (or bigger) grid of white squares behind it all. Just to give the program some extra "to do" while looping. It should go go away. (I did this when recording episodes at times because the issue were in Linux) But once we add more things, the level, especially, it should go away. If you move your mouse around the window it does not lagg?, but once you stop, it starts to lagg again.
I like your tutorials. Thank you. Let me suggest my piece of code. public enum PlayerState { IDLE(5), RUNNING(6), HIT(4); private final int spriteAmmount; PlayerState(int spriteAmmount){ this.spriteAmmount = spriteAmmount; } public int getSpriteAmmount(){ return this.spriteAmmount; } }
Hey Guys! Welcome back.
The last episode wasn´t my best work. Felt like the overall quality was not very high. But, i try to improve and i hope this one can make up for it.
The intro is stupid i know, but i loved it, had to keep it xD
Enjoy!
I believe that last episode was great! I don't think you have to be so hard on yourself :D
Grym video! Väldigt lärorik för nån som är ny. Keep it up:)
Oh wow! I wasnt expecting to actually be in the video, thanks!
Give credit where credit is due ;)
still an amazing tutorial years later, will be finishing the whole series and liking every episode. Love your pacing and explanations. ❤❤
absolute legend
I like your videos so much. They help me a lot that now I can understand the basic concepts behind the sense. It would be extremely good if you can sometimes resonate why choosing something to handle is the best fit in situations. Thank you and hope for your new videos :)
When we switch the animation, its better to reset the animationIndex back to 0, otherwise it causes the image to flicker. For example the running animation has 6 frames and suppose we are moving, and stopped when the running animation was at 6th frame. The playerAction will instantly change to IDLE but what about the animationIndex? This will cause a blank subImage to be rendered. Here is my approach for fixing it:
private void setAnimation() {
if (moving) {
if (playerAction == IDLE) {
animationIdex = 0;
playerAction = RUNNING;
}
} else {
if (playerAction == RUNNING) {
animationIdex = 0;
playerAction = IDLE;
}
}
}
Your tutorials are really great and the way you teach from scratch is satisfying and logical. you are doing great work. Could you keep it up?.
Thanks :D
case RUNNING:
return 6;
case IDLE:
return 5;
case HIT
return 4;
case JUMP:
case ATTACK_1:
case ATTACK_JUMP_1:
case ATTACK_JUMP_2:
return 3;
case GROUND:
return 2;
case FALLING:
default:
return 1;
i got you bro❤
package utils;
public class Constants {
public static class PlayerConstants{
public static final int RUNNING = 0;
public static final int IDLE = 1;
public static final int JUMP = 2;
public static final int FALLING = 3;
public static final int GROUND = 4;
public static final int HIT = 5;
public static final int ATTACK_1 = 6;
public static final int ATTACK_JUMP_1 = 7;
public static final int ATTACK_JUMP_2 = 8;
public static int GetSpriteAmount(int player_action) {
switch(player_action) {
case RUNNING:
return 6;
case IDLE:
return 5;
case HIT:
return 4;
case JUMP:
case ATTACK_1:
case ATTACK_JUMP_1:
case ATTACK_JUMP_2:
return 3;
case GROUND:
return 2;
case FALLING:
default:
return 1;
}
}
}
}
Hello, I really like this tutorial series. I am a Java developer for many years now but I never did any gaming/advance UI stuff and I really like you content!
Please note that you have something of a bug, meaning the paintComponent() method should have requestFocus(true); in it, or else on my local machine it would lose focus about 1/4 of the times.
Also consider adding private constructors to your constant classes :)
Your videos have been amazing!, thank you for putting these out there. I have honestly learned so much :)
Thanks :D
wow, your tutorials are just amazing, you helped me a lot 💕
Glad you like them! :D
Thanks for another great episode!
This is so helpful. Thank you!
Yo, man!
You make super cool content!
Thank you very much for such a detailed and exclusive review! Good luck in future career!=)
Obrigado pela aula paizao, tmj!
Great tutorial series, congrats. One questions, couldn't you use ENUM instead of those classes with constants?
Of course u can :)
Epic, as always
Thanks :D
Thanks!
Great video, you teach better than my teacher xd
Thanks :)
ty for great video! :)
Nice video, am just curious why you didnt use enums for the constants as it would've been a lot simpler
this channel is something else man, thank you for all of this great things Jesus, can believe I found you, how should I practice all of these for being good as you are? :D
Thanks man! :D
That was fast :P
hello @KaarinGaming , at 4:18 seconds , how did u get the x,y,width, height as i.
we have declare a variable right and initialize . if i do that then the in the for loop it shows error and asks me to rename the the i in for loop . please help at the earliest
Hey @KaarinGaming, your tutorials are amazing, but I have an issue when it comes to adding animations. When I try to run the program (at around 11:27), I get an exception -> Exception in thread "main" java.awt.image.RasterFormatException: (x + width) is outside of Raster. How can I resolve this? Thank you in advance.
Hello.
This error means you are trying to get a pixel outside the bounds of the image.
Recheck the code and math.
Cheers!
Hey@@KaarinGaming, thank you so much for the reply! I finally got it to work, I reversed the dimension values by mistake and thus granted exceptions in my code. Thank you so much once again for your help.
what i'm gonna do when the IDLE part is not working
hello sir at 11:03
animation[j][i] - in this line it shows j cannot be resolved to variable . how do i fix this . please let me know at earliest
Excellently helpful and extremely well structured course! But, where did you get that set of images? Did you draw it anyway or collected from any web source? After finishing this course I have planned to clone one of my favorite childhood games, which names 'Shark Attack'.. so I was wondering if I could get any website on the internet which provides some tool to create this kind of images with which we can create any (if not 3D, then 2D) animations we want. Can you tell me about any resource like that?
Thanks for the kind words! :)
There is links in description where and what I use.
Most of your needs can be found on itch.io
I saw they sell games.. I wanted a tool to build up animations as game engines like Unity are too heavy for my computer.. Anyway, how about you make a tutorial on creating 2D models in a game engine and show how to integrate those models with our java code?
i have a problem!
if i start spite moving it just moves. it doesn't stop(idle state)
what is the problem ? how can i stop him moving?
27:07
YEAH PLS HELP SOMEBODY !!!!
hey there, I think you might have written....'key pressed' contents into 'key released '.
I had same bug. Ugh actually , my dumbself caused it but, hey I solved it too! so it's okay!🥲...so it could be the same case to yours. Hope it helps!
I'm getting an error at the switch inside the updatePos() function, it just says "duplicate case". I don't know why.
Also, why you have Game class imported inside KeyboardInputs? If I do Import, I get the yellow mark saying it's not being used for anything but yours don't.
Edit: I figure, I forgot to set the up, right, down constants to 1, 2 and 3 respectively. They were all with value 0... oh well, moving on.
I downloaded the png file on your page, but the animation does not work for me. It looks fixed like a picture.What do you think is the reason?
Thanks for your video. It's very great. but i have a question.I have idle animations divided from 1 to 25. How can I merge them into one image like player_sprites.png?
where can i get the sprite images?
I'm running into a problem where if I release the key at the end of the player's animation, they flicker as if their last image is blank, but when I hold the key, the animation plays without flickering.
That's because when you change the animation, you never reset the index and animation tick to 0.
We will take care of that soon =)
I have a problem where the sprite doesn't move, it plays the animation but it just doesn't work
EDIT: nvm, in the setDirection method instead of updating the playerDirection i instead updated the player action, mb.
Any reason why you spelt it Utilz and not Utils?
I think it was to avoid naming it the same as other libraries in java.
I love this but I am trying to apply this method to a larger sprite sheet and I have no idea how to make the calculations work for it. Any tips?
You need to consider the size of each sprite, amounts of animations and the amount of sprites per animation.
Worth mentioning that collisions only work (in this code) for hitboxes smaller than a tile.
Good luck
ive lost all of my code due to a bug. any suggestions what i should do now. any how your vids are great
Shit happens.
All the code can be found on github. All you have to do is to start where you were before. =) Each branch is its own episode.
@@KaarinGaming thanks bruv
The first time it worked well but after rerunning program it doesn’t move when I click on keyboard 😢
Sir this error resolved but can you tell me why any animation is not working
Your vedios are amazing i watch it everyday but its a error of IO Exception
Hi! How did you save the icon image for a player on each row and column? On my PC, the image is moving on the left and right side and is not in the same place to see just the character moving
this happens if your dont give the right size of the sprite image.(Thats how i fixed it)
Hello Kaarin.
I don't know why when I run the project sometimes I can move the character and other times I can't... I can't find the problem
Hey.
Check out our discord server for troubleshooting and post your code question there =)
Can you tell me why any animation is not working
I've noticed a problem. When I try to move my sprite with keyboard ( I removed mouse controls 'caouse I don't want'em ), I have to do it immediately after my game launches, becaouse when I do it like a second after it launches, it won't do anything, at least I won't see it maybe it moves but repaint does not work?
Sometimes it doesn't work at all
Hey.
Add gamepanel.setfocusable true before request focus
Its a bug we fixed a few episodes back
Sometimes I play the program and it works. Then, without changin a thing, I play the program again and it doesn't get the keyboard inputs... can someone help me with that?
Yeah its a issue we fix longer down the road.
But put gamepanel.setFocusable(true) before calling .requestFocus();
@@KaarinGaming Thank you very much!
@@KaarinGaming Bro, could you tell me please in which video this problem is solved?
Hate seeing ads? Forced to watch an ad.
can anyone tell me where to find the character sprite please? I've tried other but just keep messing up the numbers
The code and the assets can be found both on my website and github. Links are in the description :)
@@KaarinGaming thank you so much I've found them on your site
Hello, great video, but I have a little problem:
For some reason, my game speeds up after a certain time. I also noticed that my animation and moving speed are slower than yours. Then, after running the program for a few minutes, the game speeds up, and everything becomes faster.
Can anyone help?
edit: It also seems that the movement is not smooth. In an earlier video, you said that this is caused by the repaint() loop and that the thread loop would fix this problem. But it seems that I still have this problem.
Hey. Does not sound like its working correct. Make sure to take a look at github for code and then there is always a discord server to check out for more help. Usually its some small bit missing in your code. :)
@@KaarinGaming Hey thanks for the quick response. I compared my code to the one on github but everything looked fine. Maybe it has something to do with my PC, maybe it's just processing it slower first and then catches up. In Unity Time.deltaTime is used for the speed of movements, to maintain a consistent speed, regardless of the system the game is played. Do you implement something similar later in the tutorials?
Np.
The game is far to simple as of now to make the game lagg or so.
Could just be the same issue I faced while developing. Long story short, it goes to fast. So it laggs. When we add the level it went away. It was a linux thing for me.
Regarding the delta you speak of, something similar is added.
We don't use delta time, but we do store past time to make sure the game can "catch up".
It comes in ep 7 or so when we fix the game loop.
@@KaarinGaming Ok. I have continued with the tutorials and after implementing Loop 2.0 the problem now apparently has gone away. Thanks again for the response.
Hello, at this point my game is already laggy, especially when I move the playe with the keyboard. I've 100% of CPU usage in one of the threads. I have played Red Dead Redemption 2 on this PC so I think it should be able to handle this game. Any ideas?
EDIT: I noticed that even when I'm not pressing any keys one CPU core goes up to 100% usage, so probably not a Keyboard Input problem.
EDIT: The game is working fine in Windows but not in Ubuntu, maybe a JVM problem?
Hey. This will go away. ( if it is what I am thinking of)
It's a thing with Ubuntu/linux.
It goes to fast in simple words.
If you were to create a 100x100 (or bigger) grid of white squares behind it all. Just to give the program some extra "to do" while looping. It should go go away. (I did this when recording episodes at times because the issue were in Linux)
But once we add more things, the level, especially, it should go away.
If you move your mouse around the window it does not lagg?, but once you stop, it starts to lagg again.
@@KaarinGaming It seems that when I move the player, the performance is better than when its idle.
@@KaarinGaming I will continue with the next episodes then...
For other people with the same problem, simply adding:
Toolkit.getDefaultToolkit().sync();
after
gamePanel.repaint();
should fix the problem.
What to do if it is not moving and the code is also correct
found the problem
@@hdteachesmath8784 sir, help me out, I cant move the character, and the only thing working is the animation
can someone explain why the hell am i getting an error "case expressions must be constant expressions" im so fucking mad at this
your sprites are not on your website or github.
They are.
I like your tutorials. Thank you.
Let me suggest my piece of code.
public enum PlayerState {
IDLE(5), RUNNING(6), HIT(4);
private final int spriteAmmount;
PlayerState(int spriteAmmount){
this.spriteAmmount = spriteAmmount;
}
public int getSpriteAmmount(){
return this.spriteAmmount;
}
}
Cheers man!
Yeah, I will use enums more in the future.