To see how to read images in IntelliJ, please check this video: kzitem.info/news/bejne/sm-g2ptmqJV4mqQ It seems quite a few people are struggling with "java.lang.IllegalArgumentException: input == null!" error. In case of this video, the error happens when the program fails to read sprite images. First, *make sure to check if your res folder has been registered as a source folder* Especially if you are not using Eclipse since the registration/resource reading process in other IDEs can be different from what I did in the video. Also, check if your file names/paths are identical to what you typed in the getPlayerImage method. Check for any unnecessary space, underscore, or other characters. *The file names and paths need to be completely identical.* If you cannot find any discrepancy, try using the same sprites in the video (the link is in the description). If you could display the images, the issue was caused by your modification so you can narrow it down. You can check if image loading is done properly or not by inserting these lines in the getPlayerImage method: System.out.println("Image loading started"); // load sprite images.... // load sprite images.... System.out.println("Image loading ended"); The loading was done properly if the second text was printed on the console. If only the first text was printed out, something went wrong during the loading and the program stopped there.
@unity_with_timoteo
2 жыл бұрын
In my case i am doing it on vs code. This error occurred. I solve it by changing the path, in my case the path is: "./../src/player/boy_right_2.png", for example.
@unity_with_timoteo
2 жыл бұрын
@Jackson Hello man. Look my answer below, it could help you!
@arelyezra6339
2 жыл бұрын
@@unity_with_timoteo did you type this "./../src/player/boy_right_2.png" only or not
@arelyezra6339
2 жыл бұрын
@Jackson did you can compile it?
@shinyspy850
2 жыл бұрын
you should pin this comment, it was very helpfull.
@organista03
2 жыл бұрын
for IntelliJ users: 1) create "res" folder: - right mouse button on main project folder -> New -> Directory -> "res" 2) mark "res" folder as Sourses Root: - right mouse button on "res" folder -> mark directory as -> Sources Root 3) create "player" folder inside "res" folder: - right mouse button on "res" folder -> new -> Package -> "player" 4) paste images in "player" folder 5) you have to add .getClassLoader() between getClass() and .getResourceAsStream() OLD: up1 = ImageIO.read(getClass().getResourceAsStream("player/boy_up_1.png")); NEW: up1 = ImageIO.read(getClass().getClassLoader().getResourceAsStream("player/boy_up_1.png"));
@darmoforeelz5857
2 жыл бұрын
This comment right here is pure gold, thank you so much ❤❤
@ogaz_
Жыл бұрын
I had to add a try catch to getPlayerImage() try { getPlayerImage(); }catch (Exception e){ System.out.println("getPlayerImage() is not working"); }
@seamus9898
Жыл бұрын
there's several solutions posted for IntelliJ, but somehow NOTHING works for me... always get NullPointerException I give up
@seamus9898
Жыл бұрын
omg I just forgot to add setDefaultValues(); getPlayerImage();" I'm so annoyed at myself :((((
@landon9889
Жыл бұрын
Thank you!
@michaelharrington5860
Жыл бұрын
My son and I finished episode 3 of your series tonight. You do an excellent job explaining everything and teach at the perfect pace. We were both so excited when the little blue haired boy started walking around. Will continue the series tomorrow with episode 4. Thank you!
@RyiSnow
Жыл бұрын
It warms my heart to hear that! I hope you and your son will keep enjoying coding :)
@yasthatsme
2 жыл бұрын
You deserve more viewers! I have learned so much from you
@RyiSnow
2 жыл бұрын
Glad it helped! Thank you for the comment.
@thenolife1957
2 жыл бұрын
Well most ppls don't play java games no more except for me
@faced2404
2 жыл бұрын
@@thenolife1957 minecraft is originally made in java
@thenolife1957
2 жыл бұрын
@@faced2404 except from that
@thenolife1957
2 жыл бұрын
Heheeee
@Alex-chesspenguin
6 ай бұрын
I’m an elementary student, this is very easy to understand, thanks!
@snarpking
2 жыл бұрын
This series is so good. I've been interested in making actual games for a long time, but I've had a lot of struggle learnign unity, and I was about ready to give up, but now I've this AMAZING series to help me use the language I'm really familiar with to make real games. I've made some pretty cool console based games before, like this whole tower defense game which was displayed to the player exclusively in text, but games like that have obviously an incredibly niche appeal. That's why I'm so excited to really branch out like this. Please keep making these amazing videos.
@Ashokkumar31082
2 жыл бұрын
wut this aint unity lol
@kira890
11 ай бұрын
@@Ashokkumar31082 I am a little late but he probably meant that he struggled with Unity, but now he found this tutorial to NOT use Unity to create his games, so that he doesn't struggle so much with making games. I hope I could enlighten you.
@lvdv4j
2 жыл бұрын
If anyone is having issues where they are getting no errors but nothing is drawn be sure to add the getPlayerImage(); method to the player constructor in the Player class. (Just under setDefaultValues ();)
@easypeezy9142
Жыл бұрын
thx
@lvdv4j
Жыл бұрын
@@easypeezy9142 Glad I could help 😄
@RealSenn
Жыл бұрын
I was stuck for 2 hours. Thank you very much!
@lvdv4j
Жыл бұрын
@@RealSenn You're welcome 😄 I'm glad I could help!
@julestheprogrammer
Жыл бұрын
TYSM!!!!
@okay1296
2 жыл бұрын
I now have ca. 3 or 4 years of programming experience in Java and Python. But sometimes I simply dont know how to implement somthing clean. Sure I could do it, but it will look like shit. You helped me a lot, how to implement all the stuff objectoriented. And a lot of times I think to abstract. Also I like your tutorials because you write all the stuff from scratch, only with the default java libarys. There are a lot of youtubers out there that would simply download Unity for 2D game development - im ok with that. But its hard to find good tutorials how to programm a 2D game engine from scratch. Also a lot of people is hating on Java, I cant understand that. Im intrested where you learned java. Keep it up, really good work and videos.
@RyiSnow
2 жыл бұрын
Yes, I also feel nothing against using engines such as Unity. If making a game is your sole purpose, using engine or library is a lot easier. That said developing it from scratch gives you deeper understanding on how game programs work and programming itself. Also, creating from scratch is fun! I'm glad you liked the videos. Always good to meet a fellow Java developer!
@marrokyoung4159
2 жыл бұрын
I came across your tutorials just a few days ago, but they are helping tremendously with making a space invaders esque game. Thank you so much Ive been learning a LOT
@cripz1436
2 жыл бұрын
I'm just happy I got my sprite character to move, since started this tutorial 2 days ago its fun learning game dev again 😁 Thanks RyiSnow
@RyiSnow
2 жыл бұрын
Glad to hear that and welcome back to game dev :D
@crackrokmccaib
2 жыл бұрын
You're so incredibly talented at what you do. I hope you have a job that appreciates your skill and pays you generously for what you can do. I hope to someday be even 1/4 the developer that you are.
@RyiSnow
2 жыл бұрын
I'm just a mediocre programmer. I'm sure you can catch up :)
@5nsou
2 жыл бұрын
Man. you are actually a legend. You deserve like more than 1 mil subscribers. Youre the greatest!
@gopnik7234
2 жыл бұрын
Great Tutorial! Ive been loving it so far! Please keep uploading! For anyone who uses another IDE than RyiSnow and can't fix the "java.lang.IllegalArgumentException: input == null!" error here are solutions for VS Code and Intellij that worked for me: For Intellij: 1. Create the "res" folder as a new package in the src folder/section 2. Create the player folder in res as player.res so that it is a package inside of the "res" package 3. Add /res to the file path in the getPlayerImage-method so that it becomes "/res/player/boy....." 4. enjoy For VS Studio: 1. Create the "res" folder in the src folder/section 2. Create the "player" folder in the "res" folder 3. Add /res to the file path in the getPlayerImage-method so that it becomes "/res/player/boy....." 4. enjoy The error most likely occurs because only the "src" folder is saved in the project source folder
@kalebwilliams4681
Жыл бұрын
THANKYOU SO MUCH
@gCoder_
7 ай бұрын
it happens to me in eclipse, i don't know why, could you please help me?
@EM0920-u7j
4 күн бұрын
Gotta love forgetting to add break at the end of my case statements and spending like 5 minutes trying to figure out why only the left sprite is rendering. Love the Tutorials so far.
@Tercer2
19 күн бұрын
Its been years since this came out and it still hold true today!! Thanks for teaching me java!
@108mmbb
2 жыл бұрын
Thank you for this tutorial. This has been very easy to follow and learn from! I'm a beginner and didn't know a thing before I started this series.
@RyiSnow
2 жыл бұрын
Glad it was helpful!
@lamagiadiele8879
Жыл бұрын
Can i say it? YOU ARE A THE BEST TEACHER THAT I EVER HAD! Thank you very much, fantastic tutorial.
@Asdpire
Жыл бұрын
If your thinking led to the same question as mine : "Wait a minute, we already tested the upPressed, downPressed etc. Why test it again just to update the sprite?" You can also just update the spritecounter in the if slot of the update method, like so : public void update(){ if(keyH.upPressed) { direction = "up"; y -= speed; spriteCounter++;} I just think it looks cleaner as a whole. Now it accomplishes the same thing with less nesting, see which you like better. I sincerely hope I'm not offending the author with my suggestions. Thank you for the instructive series!
@coldblade8795
Жыл бұрын
Thank you sir, I have always understood concepts of java but never really understood when to use them. Using your tutorial i was able to get a basic hold of 2d programming I hope you become a more popular teacher cause your teaching techniques are excellent and as always Thank You!
@moonlightmacky9055
2 жыл бұрын
Your tutorials are amazing man, keep it up!!!
@RyiSnow
2 жыл бұрын
Thanks, will do!
@droidlycodes
2 жыл бұрын
Your art skills are great, spent a few hours last night messing around with converting your guide to Android so far I have an un animated sprite that can move around the screen smoothly. I'm going to see what I can learn tonight, I feel so new lol.
@droidlycodes
2 жыл бұрын
Also I enjoy that you explain things easily, plus everything makes sense from someone that does have java experience! With your permission I may do guides on this while I'm following along to convert to Android 😁
@benn125m
2 жыл бұрын
Hello there. I just started learning a few days ago the beautiful language "java"..I am very glad I found your channel, a few video and already helped me understand more than just reading 📚. You deserve more views for sure. Keep up the good work. Wishing you a lot of success 🙌🏼
@RyiSnow
2 жыл бұрын
Thank you for your kind words!
@Talight-db9hj
3 ай бұрын
Бро, ты лучший❤ Ты единственный на кого я подписался не из вежливости, а из уважения к твоему труду и твоим знаниям!
@kanhchanaly6445
2 жыл бұрын
Thank you so much for making time to share this tutorial with us! I’m really grateful!
@RyiSnow
2 жыл бұрын
No problem :) I'm glad you liked it!
@daviddashen4070
2 жыл бұрын
I have the solution for those of you, who are struggling with the error pinned in the comments and using VS Code (but you can give it a try in your IDE). I put the pictures in a single folder called player and then I moved the folder in the src folder. And then wrote this: File f1 = new File("./src/player/ninja_up_1.png"); File f2 = new File("./src/player/ninja_up_2.png"); File f3 = new File("./src/player/ninja_down_1.png"); File f4 = new File("./src/player/ninja_down_2.png"); File f5 = new File("./src/player/ninja_left_1.png"); File f6 = new File("./src/player/ninja_left_2.png"); File f7 = new File("./src/player/ninja_right_1.png"); File f8 = new File("./src/player/ninja_right_2.png"); up1 = ImageIO.read(f1); up2 = ImageIO.read(f2); down1 = ImageIO.read(f3); down2 = ImageIO.read(f4); left1 = ImageIO.read(f5); left2 = ImageIO.read(f6); right1 = ImageIO.read(f7); right2 = ImageIO.read(f8);
@AverageLowElo69
2 жыл бұрын
I swear you are god in disguise. Thank you so much! I was going to give up since I didn’t know what to do.
@pabloa1312
2 жыл бұрын
Thank you so much! omg I literally spent HOURS looking for a solution the other way. LIFE SAVER!
@matheusguedes8432
Жыл бұрын
it worked very well in intellij, thank you very much!
@killian9843
Жыл бұрын
I use VSCode and this worked hella good. thank u very much
@brendacchebet
Жыл бұрын
I've been trying to fix this error for like days. Thankkssss
@flow2035
3 ай бұрын
Thank you mate! This is the best series in KZitem...keep going!!
@001archimedes
2 жыл бұрын
I'm following along your tutorial, and I can say I'm having a lot of fun creating this game. Thank you for putting this together and for posting the resources needed to create the game. Your explanations are very easy to follow and does not take too long.
@ghostek7792
2 жыл бұрын
I love that you did this. you're really great at teaching it srsly dude don't underestimate your talent. I greatly appreciate your videos, I'm doing this as a summer project and I make edm so I'm going to be making full tracks for different settings and looking forward to drawing little characters
@alitahboub493
Жыл бұрын
Your explanations are very clear and straight forward! Great video! (I subscribed).
@K-GamingSkyblock
Жыл бұрын
For any of those who is only getting one sprite character, make sure to add break at the end of each case in the switch statement
@jarrodmcevoy
2 жыл бұрын
Can't wait for the background tiles :)
@themasterrogerdelgado
9 ай бұрын
Enjoying this series a lot. Thank you.
@rokasvidziunas4396
Жыл бұрын
thank you so much for the amazing help
@mamapuci
2 жыл бұрын
Im here bro. Ehehe. Really, lot learning from you. Thanks again bro
@teodorairina6729
2 жыл бұрын
You are doing a great job ! I will tell my friends about you !!!
@ncthatsme
Жыл бұрын
Thank you so much. This has been really fun and very informative.
@NLogSpace
Жыл бұрын
Nice video, I really enjoy your content! I also like to develop 2D tile-based games in Java, this series seems to be a good resource for me! Do you also use the entity component system (ECS) pattern for any of your games? I recently found out about it and I think it is a great way to structure code for this kind of games.
@BigManBand22
2 жыл бұрын
You are a great teacher man! Arigato!
@LouShunt
2 жыл бұрын
Hey I love your videos. But i got a question about the animation. The update method is based on the number of FPS. Which means that with the system you made, a person with 30 fps on the game will have 2x slower animation and a person with 120 fps 2x faster. Is there a way to have the same animation speed regardless of fps?
@RyiSnow
2 жыл бұрын
Yes, I think you can set the speed based on fps. Example: int speed = 240/FPS; This returns 4 if fps is 60 and returns 8 if fps is 30 so the player speed stays the same. That said if you set fps 241 or more, the speed becomes 0 (since int doesn't accept decimal) so player won't move at all in that case. So probably you'll need to change it to double and arrange the code a little bit. Like counting decimal behind the scene and when it hits 1, apply the movement or something.
@LouShunt
2 жыл бұрын
@@RyiSnow Great idea! Thank you I will try it
@RyiSnow
2 жыл бұрын
Hi, I just realized that you were asking about the animation, not the player's movement speed. Maybe you've already figured it out but you can also set the sprite counter based on fps so the interval between sprite 1 and 2 stays the same.
@mikemazanetz4183
7 ай бұрын
thank you very much for these wonderful video tutorials. An excellent resource !
@hizokadarkwolf
Жыл бұрын
Incredible. What about storing the sprites inside an array? And better, having one single sprite sheet file and changing the position? For performance/memory. I think I will add these if it's not done on the videos to my version on my repository. Thanks a lot. Very fun tutorial.
@SlothfulSage285
2 жыл бұрын
I was trying to limit myself to one video a night, but I could not help it and decided to do another! :)
@brinklebros7136
7 ай бұрын
I LOVE YOUR VIDEOS!. I made a few tweaks to this code, there I made use of arrays for my animation frames since i had 4 frames per walk cycle. I also made it so I could tweak the timing per frame more easily, and a few other things. its functionally the same but i love this engine your making and im learning a ton.
@kylellsuperman
5 ай бұрын
I'm really enjoying this series so far. it's getting me back on my feet with a lot of my coding knowledge. i just noticed that you're putting a lot of your boolleans into your if statements with a equivalency check when boolleans are automatically true or false values. I just wanted to point out you could write it as "if(keyH.upPressed)" instead of "if(keyH.upPressed == true)" to save some space. I hope this can help someone out there. (Again, this only works for boollean variables.)
@mistiical3033
2 жыл бұрын
Hello, in class Player when you import Gamepanel and Keyhandler you get option to do main.Gamepanl etc i do not get these options when i type it in myself I get an error saying the import main cannot be resolved. any solutions, Thanks.
@silviuzlota6458
2 жыл бұрын
Cool video , I learned a lot from you.Thanks
@RedlikMusic
2 жыл бұрын
you can also use arrays to storage the images and then iterate through the values c:
@Team6OWG
Жыл бұрын
How????? I am confused becasue we store BufferedImage objects, so we can create one 1 arrayList called images, that has all of the, but are we still creating up1, up2, down1, down2? or dont and just do image.add(ImageIO.read(getClass....etc ? But how do you get the string to change for "/player/boy_left1... or /player/boy_right2"???????? Can you show what you did?
@r4c_h3ll
Жыл бұрын
@@Team6OWG @REDLIK share dude!! ((:
@Sviskebisk
Жыл бұрын
Thank you Ryi
@RyiSnow
Жыл бұрын
Thank you for your support!!! I hope you'll enjoy the series :)
@NikitaBomba112
Жыл бұрын
Thanks you so much for this video!
@noahbarger1
2 жыл бұрын
If the sprite you made has more than 2 images, and when it stops animating you want it to go back to the first image, then after the "if" statement, put: if (keyH.upPressed || keyH... else { spriteNum = 1; }
@LEALCUTSS
Жыл бұрын
Thanks, very informative video!
@IseOnCrack
2 жыл бұрын
Wow, that's a really good and in depth tutorial, good job! I'm following the tutorial but im trying to do some things in "my way", for exemple, why dont you use entity as an abstract class? Instead of the 4 if you used for sprite number, my spriteNum grows every 10 spriteCounter (like yours), but for select the image in the switch i use if(spriteNum%2==0) , i find it a bit more elegant. Pls dont use keyHandler==true XD. Good job again!
@anicepineapple9067
Жыл бұрын
For anyone wondering how to resolve the error in VS code. Just right click on the res folder and select "add folder to java source path." this worked for me.
@thehandleisuseless
2 жыл бұрын
crazy to think that Minecraft was made like this, wow
@juandebenedetti2884
Жыл бұрын
What do you mean that MC was made like that? Minecraft was made with LWJGL to be able to draw using OpenGL, this being a hardware representation. This tutorial uses Swing, and Swing uses software rendering. The difference between the two is that hardware rendering has countless benefits. But I'm not saying that learning Swing to make video games is bad, don't get me wrong. RyiSnow teaches us the basics of 2D game development, which is essential if you want to get into something deeper like OpenGL.
@apro8723
9 ай бұрын
bro u mean the og legend of zelda bro.... dont get ur games mixed up.
@neon-mask5171
Жыл бұрын
i dont know what is happening my player sprite is not showing its showing the white rectangle only even though i have cut out the code for it. please help.
@weptashka
2 жыл бұрын
You make awesome tutorials! Thank you!
@alex_tremo255
5 ай бұрын
3k like. Thanks for your tutorials man
@playLaF
Ай бұрын
Hi @RyiSnow I have a question, is it possible for the sprites to move diagonally? Thanks!
@kyletran6160
Жыл бұрын
bro's good at drawing, i cant
@S1mplector
Ай бұрын
Hey, RyiSnow! I have been following your tutorial and this has been amazing so far. I am excited to go through all of the videos on this series, thank you so much for the effort! I wanted to add something to the character walking animation. I updated the Player class slightly so it switches between walking sprites when a movement key is held and displays a static sprite when the key is released, by using a boolean. package entity; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import main.GamePanel; import main.KeyHandler; public class Player extends Entity { GamePanel gp; KeyHandler keyH; public Player(GamePanel gp, KeyHandler keyH) { this.gp = gp; this.keyH = keyH; setDefaultValues(); getPlayerImage(); } public void setDefaultValues() { x = 100; y = 100; speed = 4; direction = "down"; } public void getPlayerImage() { try { // static images up1 = ImageIO.read(getClass().getResourceAsStream("/player/up.png")); down1 = ImageIO.read(getClass().getResourceAsStream("/player/down.png")); left1 = ImageIO.read(getClass().getResourceAsStream("/player/left.png")); right1 = ImageIO.read(getClass().getResourceAsStream("/player/right.png")); // animations up2 = ImageIO.read(getClass().getResourceAsStream("/player/up2.png")); up3 = ImageIO.read(getClass().getResourceAsStream("/player/up3.png")); down2 = ImageIO.read(getClass().getResourceAsStream("/player/down2.png")); down3 = ImageIO.read(getClass().getResourceAsStream("/player/down3.png")); left2 = ImageIO.read(getClass().getResourceAsStream("/player/left2.png")); left3 = ImageIO.read(getClass().getResourceAsStream("/player/left3.png")); right2 = ImageIO.read(getClass().getResourceAsStream("/player/right2.png")); right3 = ImageIO.read(getClass().getResourceAsStream("/player/right3.png")); } catch(IOException e) { e.printStackTrace(); } } public void update() { boolean moving = false; if (keyH.upPressed || keyH.downPressed || keyH.leftPressed || keyH.rightPressed) { moving = true; if (keyH.upPressed) { direction = "up"; y -= speed; } else if (keyH.downPressed) { direction = "down"; y += speed; } else if (keyH.leftPressed) { direction = "left"; x -= speed; } else if (keyH.rightPressed) { direction = "right"; x += speed; } spriteCounter++; if (spriteCounter > 12) { if (spriteNum == 1) { spriteNum = 2; } else if (spriteNum == 2) { spriteNum = 1; } spriteCounter = 0; } } if (!moving) { spriteNum = 1; // Reset to the static sprite when not moving } } public void draw(Graphics2D g2) { BufferedImage image = null; switch (direction) { case "up": if (keyH.upPressed) { image = (spriteNum == 1) ? up2 : up3; } else { image = up1; } break; case "down": if (keyH.downPressed) { image = (spriteNum == 1) ? down2 : down3; } else { image = down1; } break; case "left": if (keyH.leftPressed) { image = (spriteNum == 1) ? left2 : left3; } else { image = left1; } break; case "right": if (keyH.rightPressed) { image = (spriteNum == 1) ? right2 : right3; } else { image = right1; } break; } g2.drawImage(image, x, y, gp.tileSize, gp.tileSize, null); } } I have already learned so much, thank you so much for it again!
@ivangamer2888
7 ай бұрын
I'm making a game as a final project (the game is Tron the one of the movie, the motorcycles that leave a wall of light behind them), the thing is that I don't know how to make that wall and I've been searching a lot and I can't find how to do it. I don't know if you or someone from the community could help me, thank you very much in advance.
@ochkoochkeevich9123
Жыл бұрын
Hello from Russia!!! You deserve more viewers)
@smartestpotato2127
2 жыл бұрын
I’ve been following your tutorials to the t so far, but when after shifting the key input stuff to the player class and after clicking run, the square doesn’t move at all, do you have any clue what the problem could be? no errors are popping up, it’s just not getting my key inputs for some reason edit - never mind, I forgot to put the player update inside the game panel update
@selimsmajlovic7871
Жыл бұрын
I require help. When I try to import "main.GamePanel" and "main.KeyHandler" nothing shows up. When I write the imports manualy, it is still an error, like it does not recognise the imports or something. Does anyone have an answer to this?
@idkwhoami9986
Жыл бұрын
not sure if you still need help but.. i had a similar problem, turns out it was because my GamePanel and KeyHandler files were not in a "main" folder. when I added them to a folder called "main", it worked as it did in the video
@dovydasbalciunas5002
11 ай бұрын
Hey man! I'm trying to master java right now and I got a question. Were you just like messing around or is creating games your passion? Are you a game developer?
@doxuantruong04
3 ай бұрын
i use netbeans IDE and i don't play program, can use help me?
@suiz137
Жыл бұрын
5:14 can tell me why my line 'Player player = new Player(this.keyH);' is error constructor undefined ?
@solareclipsedudefinale9026
Жыл бұрын
Instead of "this.keyH", do "this, keyH" because we want to pass 2 arguments to the constructor
@saschapolaschek2715
2 жыл бұрын
Nice video man!
@RyiSnow
2 жыл бұрын
Thanks!
@Lazullien
2 жыл бұрын
this might be a little late but if i switch to bufferedimage, not even drawing the images, just assigning the pngs, my key binding seems to break, whenever i stop calling the method that assigns the pngs it goes back to normal, if i add any other functions with the images on they work just fine, but the key binding breaks, i'm not sure how keybinding focus works but it still seems quite awful
@Lazullien
2 жыл бұрын
nevermind i'm leaving this comment here for people with the same problem, key binding's default focus is just as crappy as keylistener's, put JComponent.WHEN_IN_FOCUSED_WINDOW inside the getInputMap()'s parameter to fix this
@davidbijaksantoso-085
Жыл бұрын
is there a way to make another image animation (I want to add an idle animation when not pressing any keys)?
@lordkuuba3517
2 жыл бұрын
Hi! I have some problem with animation how to add more frames (4) ?
@maximhanzely1988
2 жыл бұрын
18:57 u can try adding something like this : else if (spriteNum == 2) { spriteNum = 3; } else if (spriteNum == 3) { spriteNum = 4; } before he adds this: else if (spriteNum == 8) { spriteNum = 1; } it worked for me idk if its good but hey it works
@zitrix7848
2 жыл бұрын
*my sprites are not drawing to the screen, i used the same sprites from video description everything loads in without any error but the sprites won't load to screen please help*
@lvdv4j
2 жыл бұрын
Did you add the getPlayerImage(); method to the player constructor in the Player class? I had the same problem and this was my solution
@flow2035
3 ай бұрын
Awesome!!!
@pietrosica5265
2 жыл бұрын
I have this problem : i can move the rectangle so i guess in the key listener class and update method there s no error but when i import the images (i just copied like in the video) and run the program i can see my player in the defaultValues position and direction so the sprites are loaded but i can’t move it (i tried to comment the getPlayerImage(); and the g2.drawImage(x,y,gp.tileSize,gp.tileSize,null) and i wrote again g2.fillRect(x,y,gp.tileSize, ,gp.tileSize) , so i can move again the rectangle , but with te image loaded i can’t move the player and the program runs with no error
@natesannatesan2220
Жыл бұрын
For me too
@samirunlu9900
Жыл бұрын
@@natesannatesan2220 I used a different key instead (VK_W,A,D,X OR SOMETHING 😊) , the arrow up, down, left, right (VK_UP,DOWN,LEFT,RIGHT) and it worked 😊. had the same problem hopefully it helped.
@miguelmalini2635
Жыл бұрын
same
@tito-kz1fm
2 жыл бұрын
Hey, the character only appearing when going D key, WAS keys won't show character? can you help me with that?
@JCIgaming
2 жыл бұрын
In case you haven't figured it out yet, you are probably missing some breaks in switch statement. It's such a stupid mistake but it slipped by me and hopefully its the same solution for you.
@kenanahmed
Жыл бұрын
subscribed immediately
@Magnezone962
7 ай бұрын
I wanted to add 2 images so that AWSD key are player 1 and the arrow keys are player 2
@yajie7756
2 жыл бұрын
You are just so amazing !
@Zuko0847
Жыл бұрын
1:39 for some reason it doesn't show me the import option, any idea why? btw thanks a lot for the video, you're doing an amazing job!
@idkafknhandlebrah
Жыл бұрын
it doesnt give me import player option at 2:38
@idkafknhandlebrah
Жыл бұрын
nvm fixed it
@bluestreak711
Жыл бұрын
God is good and I am getting a little better in troubleshooting. the mistake I made that should be avoided on this video was that I did not include the line of code, "import java.awt.image.BufferedImage; " right after the " package entity;" in the Entity class. To all my peers, I would encourage you to make sure all your imports are added. This will solve a lot of your problems. To our teacher @RyiSnow, for future tutorials, please call more attention to when you import something or click to import something. Sometimes you click so fast and if I blink, I miss where you click to have Eclipse automatically import something. Sometimes, I do not ever see it, but I know it is there. So far, I have been able to use Eclipse to track it down. Other Input: MSpaint and Gimp both are good alternatives to make Pixel art. The only problem with MSpaint is that it is difficult to make it 16x16px, but if you make your draw area close to square and draw your images, you can use Gimp to both resize your image to 16x16px and a few simple clicks will make the white background transparent. You should be able to do everything inside of Gimp, but I am not yet well versed with Gimp as I am MsPaint as of yet. Gimp is almost as powerful as Photoshop and is completely free and opensource, so it is worth learning. Fun Thought: I have considered taking photos of myself, and other people, in all of the same poses as your little boy sprite and inserting that into the game. Yes, I could probably do animated pixel art also, but I am talking about just unedited pictures except for the 16x16px resizing and making the background transparent.
@megha9307
Жыл бұрын
Hey man I keep getting this error and I think it has something to do with imports you think you can take a look ---------------------------------- package entity; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import main.GamePanel; import main.KeyHandler; public class Player extends Entity{ GamePanel gp; KeyHandler keyH; public Player(GamePanel gp, KeyHandler keyH) { this.gp = gp; this.keyH = keyH; setDefaultValues(); getPlayerImage(); } public void setDefaultValues() { x = 100; y = 100; speed = 4; direction = "down"; } public void getPlayerImage() { try { down1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_1.png")); down2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_down_2.png")); up1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_1.png")); up2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_up_2.png")); right1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_1.png")); right2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_right_2.png")); left1 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_1.png")); left2 = ImageIO.read(getClass().getResourceAsStream("/player/boy_left_2.png")); }catch (IOException e) { e.printStackTrace(); } } public void update() { if (keyH.upPressed == true) { direction = "up"; y -= speed; } else if(keyH.downPressed == true) { direction = "down"; y += speed; } else if(keyH.leftPressed == true) { direction = "left"; x -= speed; } else if(keyH.rightPressed == true) { direction = "right"; x += speed; } } public void draw(Graphics2D g2) { BufferedImage image = null; switch(direction) { case"up": image = up1; break; case"down": image = down1; break; case"right": image = right1; break; case"left": image = left1; break; } g2.drawImage(image, x, y, gp.tileSize, gp.tileSize, null); } }
@megha9307
Жыл бұрын
The error that im getting is The type java.io.IOException cannot be resolved. It is indirectly referenced from required type java.awt.Font
@bluestreak711
Жыл бұрын
@@megha9307 I am going to take a wild guess at what your problem is, but without seeing all of your code and not just your player class, it is hard to tell, but I am going to give you a few things to look for and there is a good chance you will find it on your own and be a better programmer for it. First, see if it helps to add import javax.imageio.ImageIO; to your entity class for reasons I explain below. If that doesn't work and if you are using eclipse like Ryisnow and me, read the error line and see exactly what it reads. It will give you a lot of clues. Remember that your player class extends the entity class. You pasted your code for the Player class. If you happen to forget an import in your Entity class, it can cause an error on your Player class and cause it not to work. Be watchful of each time Ryi uses a variable or attribute from another class. You might be working in the Player class and think you should import something there when you should import something to the Entity class because that is where that item in question originates. The same goes for making variables public when you call them from a different class than where they were declared. In a video coming up there is an instance where Ryi forgets to make a certain variable public and has to go back and make it public, so the program will work. I do not remember if this applies to both folders and packages, but this definitely applies to packages. Each time Ryi has you create a new package or a new folder, you have to import your main class or some other class to that new class you just created or vice versa, so it is not isolated and can talk to the rest of your program. Eclipse will often do this with a couple of clicks and Ryisnow will click so fast to generate that import automatically that if you blink, I assure you will miss it. I have also had a few instances where Eclipse offered to generate that import line of code for Ryisnow, but it wouldn't do it for me, so I had to read the error details very carefully and figure out which import line of code I needed to add and add it manually. Good luck and comment back when you figure it out because these comments help other people with their code also!
@bluestreak711
Жыл бұрын
@@megha9307 Libbania Reyes had some good suggestions of a few things to check in a comment below also.
@jamesschraffl6820
2 жыл бұрын
Thank you so much ryi
@RyiSnow
2 жыл бұрын
Not at all. It's been a while since I uploaded those 2D demo videos and you commented on them. They say being able to understand it and being able to explain it to others are different thing and that was so true haha. It took longer than I had expected and I appreciate your patience. I hope you're enjoying this series!
@RamdomOfInternet
10 ай бұрын
I change language because English is more comfortable for me. Day1: I got to this part of the video today and the truth is it took me a bit... At least I'm understanding it.
@CanePazzoHD
2 жыл бұрын
Dear Ryisnow, thank you for the immense work you are doing. I have recently started to follow your tutorials step by step. I’m having a great time and you’re very clear in your explanation. I have a problem I can’t solve, can you help me? When I press start, the character moves in the direction I have indicated. At some point, however, it freezes and does not move anymore despite me pressing the command on the keyboard. Shortly after it starts moving again and so on it stops again. The FPS are fixed at 60, it seems to me that everything I marked on the KeyHandler is correct... what can it be? Thank you very much for your availability!
@luandkg
2 жыл бұрын
Amazing 👏🏻👏🏻👏🏻👏🏻👏🏻
@brayanavilacaravaca4964
Жыл бұрын
i have a problem, the class KeyHander no works for some reason.. And I did it the same of the video... Any sugestions?
@rinesamorina7465
2 жыл бұрын
I can get the image to show on the window but not move (and I can also get the rectangle to move but only if its a rectangle not the image). There doesn't seem to be any syntax errors so I don't know what I did wrong. Pls help
@RyiSnow
2 жыл бұрын
Can I see your Player class?
@rinesamorina7465
2 жыл бұрын
@@RyiSnow sure where do i send it
@RyiSnow
2 жыл бұрын
You can paste it here.
@rinesamorina7465
2 жыл бұрын
@RyiSnow actually now it doesnt work for the rectangle too, it just paints it but it doesnt move
@natesannatesan2220
Жыл бұрын
Same here
@TheG60528XiJinPing
5 ай бұрын
for me its only showing one direction of image
@XtoInf
2 жыл бұрын
My sprite seems to only change to the right and up sprite’s
@TamLe-yh3eg
9 ай бұрын
for anyone want the character to move diagonally, just replace all else if conditions in update method to all if conditions
@marinasalonso2716
2 жыл бұрын
Hello, I have a problem with my getPlayerImage() method, when I start the program an error occurred and it says "Caused by: java.lang.IllegalArgumentException: input == null!", I tried to change the path of my pictures but nothing changed. I have the same code as you but the only difference is the path for the pictures.
@RyiSnow
2 жыл бұрын
Sounds like the program is failing to load your image. Are you using png file? Also, check if you have spelled the file names right such as not forgetting to type underscore, back slash etc... that often happens.
@marinasalonso2716
2 жыл бұрын
@@RyiSnow To test the method I used your sprites so the image isn't a problem, I think. And I thought that the path was wrong too, but I checked several times and nothing
@RyiSnow
2 жыл бұрын
Can I see your Player class? You can paste it here.
@marinasalonso2716
2 жыл бұрын
@@RyiSnow I sent like 5 times a message with my git depository, cause I couldn't write my code on commentary of this video, I don't know why, so is there another way to show you the code ?
@RyiSnow
2 жыл бұрын
@@marinasalonso2716 You cannot paste external link in KZitem comment. It most likely gets regarded as spam. You cannot directly copy & paste your code here? If it still doesn't work, you can contact me via twitter.
@cedricsahaghian1605
Жыл бұрын
Thank you RyiSnow!!
@JZSNooB
2 жыл бұрын
Ah, so I see you are using 8 different images for the player sprite. Would you ever optimize the animation system to support reflections, such that you only use 4 unique sprites? Like "Boy_down_2" is just "Boy_down_1" but flipped on the y-axis, and left_1 and left_2 are just right_1 and right_2, but reflected over y, and so on.
@RyiSnow
2 жыл бұрын
That sounds like an interesting idea (never thought about it) but probably won't fit this game because not every character is symmetrical. For example, if a character is holding a sword on their right hand, flipping the sprite will produce a strange result (the character will be holding the sword with his left hand). So I think I will stick to the current system for the time being. Thank you for the suggestion though :)
@JZSNooB
2 жыл бұрын
@@RyiSnow Understandable. In that sword senario, that definitely wouldn't work, but I just figured that if you're going for a retro style graphics, that working within some artistical limitations like a limited color palette (or in this case a limited number of keyframes) might spark some creativity or just be a fun extra challenge. Ofcourse though it is your project, and I'll watch the series regardless!
@kristovish
2 жыл бұрын
Hello! when running the program. it starts and displays the player's images. and it works fine when pressing A S W but when pressing D to go right. the image is not displayed. what's next?? I can't find the problem
@kennethvolchok4122
2 жыл бұрын
It happpens in the same way for em
@NeoZondix
2 жыл бұрын
Hi. Nice video. It helped a lot. Although, from a professional standpoint, some technical decisions have room for improvement, e.g using if(spritenum==1[, 2]) instead of spritenum = (spritenum + 1) % 2. Same goes for starting numeration for 1 instead of 0. Otherwise, this tutorial was very helpful.
@henrikcederlof8444
Жыл бұрын
Took me a day only to find out i missed .png that solved all the problems i faced xD
@thenewsonatrain
Жыл бұрын
omg legend. tysm. i did too, and missed it!
@TulhoKay
Жыл бұрын
when you created the player, you passed this, here you don't accept it at all, it keeps asking for cast. I do it to later give an error of creating local variable.
@naokhie9373
Жыл бұрын
why cant I import player in the game panel class? thanks
@Gytimaru
2 жыл бұрын
I was listening while coding and didn't realize that when you said "player *dot* boy_up_1.png" you meant "player/boy_up_1.png"... I was so confused when nothing worked in eclipse, even changing the folder multiple times, I had to rewatch a third time to realize it!
@pauldhartley
Ай бұрын
If you are going to use the keyPress data in the braw method, why have a direction variable at all! I did enjoy your video very much and is helping me to understand sprites etc. Thank you
@SJAMS_
2 жыл бұрын
I love these tutorials/walkthroughs so much! I just have one question though when using Netbeans I can't get the walking sprites to load and I am not getting any errors in my code. The normal standing in place sprites show but when I do the same code as shown in the video only the eight sprite will load in and everything else is a blank and it isn't even "walking"? I have no clue how to fix this issue. Any other Netbean users running into the same thing? Thank you!
@Ramej
Жыл бұрын
solution: delete netbeans 👍😁 (like i did) cuz theres no source folder in it and switched to eclipse
Пікірлер: 559