"For now it's not a big difference" I mean, i am almost a complete illiterate programming wise, but you decreased the rendering time by around a 30%, correct me if i am wrong. Anyway, i really like dev videos like this one. I feel that a lot of pc games nowadays come out without proper optimizations. And somehow, people has grown used to run games by brute force regardless of wether it should or it shouldn't take so many resources. I encourage you to do more videos about optimizations like this one! And looking forward for the next part!
I was thinking "Man, this turned out to be a pretty boring episode" haha so I'm glad you enjoyed it! Once we add everything in the second half, the program takes about 3,000,000 nanoseconds to draw without pre-scaling (in my environment at least) and we can reduce it to about 1,500,000 nanoseconds with this method so the more we add stuff, the more this kind of optimization becomes effective ;)
*If your image background is turning black, or your images are turning white when drawing, i've found the solution* --> When RyiSnow was writing the UtilityTool class, he put the image type in the scaleImage method as a random (don't know if "random" is the right word) one -->(BufferedImage scaledImage = new BufferedImage(width, height, original.getType()), "original.getType()" is what I mean, it will return an int which is the imageType chosen, and can vary), I don't really know why but it gives that error. *The solution is to substitute "original.getType()" for "2"* (specify the imageType just for imageType 2). it will look like this "BufferedImage scaledImage = new BufferedImage(width, height, 2);". It worked for me so it might as well work for you, I hope, and sorry if my words are very hard to understand lol.
looking at the playlist is awe inspiring. I cannot wait to learn how to transition maps and a trade system. Those two things are going to REALLY make this game feel like it gained some legs
@alex_tremo255 i have plans and I think watching Pirate software really got me going to search out for where to learn. This guy deserves a ton more love for explaining and showing what hes doing
IN CASE ANYONE ARE EXPERIENCING IMAGES TURNING BLACK AFTER RESIZING. I made my new tiles in PhotoPea(seems like the software is somehow related) and for some reason the images wont scale properly in Java code. I remade my tiles with Piskel, now everything works fine.. I had the same issue in episode 18 when I tried creating my own Heart pixel images in PhotoPea. I think it compressed the image files alot upon exporting or something.
My performance decreased after these additions, and I don't know why. It went from around 9.000.000 on average to over 11.000.000. Also, you didn't remove the scaling from the draw() method of the SuperObject class
at min 3:20, if you want to control the variable based on previous state and set it to opposite, you can simply write: checkDrawTime = !checkDrawTime Another thing I see you write everywhere is: if (condition == true) or if(condition == false) This is not necessary since the if statement evaluates to true or false the expression inside the parenthesis, you can simply write: if (condition) or if (!condition)
I have a question. Everything works fine on my end, nothing to do with bugfixing or debugging. But, wouldn't it be a good idea to implement the setup method in the Entity class and call it from Player class? I think it would work better if you also want to load sprites for mobs, NPCs or other entities. Also, can't we overload the method? We can have an index one and a non-index one. Lmk if its a good idea pls!
The SuperObject class is parent class of all the OBJ_subclasses. And even the draw(...)-Method of SuperObject class has GamePanel gp as parameter. We should let inherit that gp for the subclasses instead of giving every single subclass that reference by hand. I tried to organize it myself, but then there is the AssetSetter class too, which is acting with setObject(). This three classes we should handle different. And even I think we should implement a single GameObject class for all game objects, including Entity. Would be really fine if you reorganize these classes, cause I will do definitely some failures.^^ 😉😉😉😉
Hmm, I really didn't like the fact the object size was tied to tile size, so I created a separate final int in SuperObject called OBJECT_DEFAULT_SIZE. That way I didn't have to put gamepanel in the objects, which felt weird and unintuitive to me. I feel like maybe final values that are just set and can never be changed should maybe be defined elsewhere, like in settings or something, and then load all those values at once. So you have a Settings class or something, and on startup, Settings reads settings off a file and decides stuff like tile size and object size. I don't know if that's necessarily the best idea, but it feels weird going back to gamepanel for everything.
Correct me if i'm wrong, but i think you made a mistake. In SuperObject class you are still scaling the images and in every object class it seems like you forgot actually set the image to scaled image. You just called the scaleImage function and didn't do anythink with the BufferedImage it returned.
@@MrCricriboy Yes he should have. Doing that in all object files plus removing the gp.tileSize, gp.tileSize out of the g2.draw image line in the SuperObject class should fix it.
@RyiSnow May i ask a Question? Do we Really need to display the drawtime on screen?? Cant we just code the draw time and make the game smooth but just not display it?? if its necessary then alright
In case anyone was getting the vertical black lines in their game when they followed the tutorial, go into your UtilityTool class, find the BufferedImage method, and change g2.drawImage(original, 3, 0, width, height, null); to g2.drawImage(original, 0, 0, width, height, null); //x default 3. setting it to 0 removed the gaps
I'm a little confused as to why you declaring Gamepanel gp and this.gp = gp in every object. Since we're passing gp as a parameter when we call our objects, wouldn't the public OBJ_ObjectName(GamePanel gp), as well as the uTool code, be enough??
I followed all the video and I have a problem: the scaleImage method provides an exception, Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0. I just have no idea on how to solve it, do anyone knows what could be?
18:53 the "uTool.scaleImage(image, gp.tileSize, gp.tileSize);" for the OBJ_Key etc classes doesnt appear to do anything since the SuperObject() class draw() method still uses "g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);" and if you remove "gp.tileSize, gp.tileSize" from g2.drawImage(), the scaling never happens even though uTool.scaleImage is implemented in the OBJ_Key() class. You just end up with really tiny objects drawn on the map in that case. I dont know what the solution is.
To make the setup sequence a bit more versatile one could simply add in the extension as a String. This way if the file was a jpeg, png, tiff or other file you could just use that specific version to access it. Also you kind of forgot to set the objects images to the scaled image after scaling them. Also you forgot to remove the width and height from the draw image class itself since we have already scaled them before the images get rendered.
I hope you're having a great time. i ran into an issue when i'm rendering this way, my player is turning black and white when i renders this way, would you know why this would happen?
I don't know exactly why this is happening, but after applying these changes my player character is now tiny. I've checked both the Util and Player classes, and both are identical to your code. Any idea on why this happens?
@@RyiSnow Well I checked every line of code and I found the error. I called the scaleImage method but didn't actually set the image equal to it. So it wasn't actually scaling the image. Thanks for your time and keep up the great work!
@@КсюшаАртси make sure you didn’t do what I did and set the image equal to the scaleImage method instead of just calling it. I haven’t gone back to this tutorial in a while so I don’t remember anything else, hopefully that fixes your problem
I don't know what happened, but when I start the game, "DrawTime" is already being shown on the screen and the shortcut Key doesn't work, not even to take it off the screen. Can you help me?
Maybe you have another size of your sprites and this is why player is moving faster. We change render style now, maybe also it changes for you the size. Greetings!
@@kamilgren8117 Thank you for your reply. I didn't follow the improve rendering step or I skip that and continue the tutorial. So far my modified game is still good. Hehe.
In objects door, etc.. you forgot to set resized image bufferedImage = utilityTool.scaleImage(bufferedImage, gamePanel.tileSize, gamePanel.tileSize); and in SuperObject draw remove resizing.
Loving the tutorial series dude! Unfortunately after following this video, I get the following error when trying to run the game: Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0 at java.awt.image.BufferedImage.(BufferedImage.java:501) at main.UtilityTool.scaleImage(UtilityTool.java:9) at tile.TileManager.setup(TileManager.java:46) at tile.TileManager.getTileImage(TileManager.java:30) at tile.TileManager.(TileManager.java:24) at main.GamePanel.(GamePanel.java:32) at main.Main.main(Main.java:13) Useful lines of code to know: TileManager.setup(TileManager.java:46) is this line: tile[index].image = uTool.scaleImage(tile[index].image, gp.tileSize, gp.tileSize); UtilityTool.scaleImage(UtilityTool.java:9) is this line: BufferedImage scaledImage = new BufferedImage(width,height,original.getType()); After debugging and finding the source of problem, it seems as my code fires the error just after running the first line in the getTileImage() method from the TitleManager class: setup(0,"grass1",false); I think the program has trouble finding the image type from an int but I could be way off. I think the problem is either coming from the UtilityTool or TileManager class, just for a sense of direction. Any pointers or help would be massively appreciated as I want to carry on with these tutorials! :D
@RyiSnow ,Can you please explain me why my drawtime has moments where it changes from 5milion to 14 million all of the sudden and black lines appear between my tiles?RyiSnow
I noticed that if you implemnts the stopping camera at the edges of the map when you at the adges the time to draw is x10 than the time to draw when you are in the middle let me know what do you think about that and if you have idea to optimaze this too
I couldn't seem to get any improvements with this. I'm sure I messed up the implementation somewhere. I don't suppose you have idea what I could have missed that would cause it to not actually improve the time?
Everything is fine but I have a problem. In my drawTime it is showing me a number like this 259543180941500 and it still increasing not just jumping around this number. What happening to my code when everythink what I done is like your code? Thank you for any answer.
I have a solution guys but I don't understand why on video it is working and in my situation didn't, So solution was I must put drawStart out of if statement because it never write time into this value. After then I have everything working good.
Man i have this problem Exception in thread "main" java.lang.IllegalArgumentException: input == null! , i don't know what to do i have been searching for help on the internet but found nothing.
image = ImageIO.read(getClass().getResourceAsStream("/player/" + imageName + ".png")); The problem was ths .png was " .png" but you can't have the space between.
Question I did everything and it works but when I turn it into an .jar file it doesn't BUT when I use the old image rendering system it works. is there somethings wrong with my code or the whole new rendering system?
Thank you very much for the lesson. It turns out very cool. I'm trying to make a game for a college course project. But I don’t know how to zoom the camera, for example, if I want, for example, when I turn on a certain function in the menu or press a key, my camera will zoom in twice, for example... Guys, if you know how to do this using the example of this cool game, please share a source or a hint if it’s not difficult for you.
Please anyone help I'm getting the following error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot read field "image" because "this.tile[tileNum]" is null
I don't know what I did wrong but my games screen went blank an didn't load anything and couldn't close and then I could hear my laptop struggling to comprehend the stupidity of whatever mistake I made while the fans kept getting louder and louder... so I'm sure that's a good sign😂
Sorry I don't understand what you mean. Can you describe the situation in more detail (the error message you are getting, which line is causing it, when the issue started etc.)?
Hi! Can you please explain me why my drawtime has moments where it changes from 100000 to 14 million all of the sudden and black lines appear between my tiles?
Hello. I am getting the below mentioned error after following this video. If anyone can help me out with this it will be very helpful since i want to continue the playlist and complete this game. thank you. Error: Exception in thread "main" java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356) at tile.TileManager.setup(TileManager.java:48) at tile.TileManager.getTileImage(TileManager.java:34) at tile.TileManager.(TileManager.java:28) at main.GamePanel.(GamePanel.java:36) at main.main.main(main.java:13)
Can someone maybe help? What I did wrong?^^' I get this error message: "Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0 at java.desktop/java.awt.image.BufferedImage.(BufferedImage.java:501) at main.UtilityTool.scaleImage(UtilityTool.java:10) at tile.TileManager.setup(TileManager.java:96) at tile.TileManager.getTileImage(TileManager.java:36) at tile.TileManager.(TileManager.java:28) at main.GamePanel.(GamePanel.java:33) at main.Main.main(Main.java:19)"
ooookay, I solved it xD hahaa finally can move on :P (my changed code of the UtilityTool-method is right below, for anyone having the same issue :)) Btw, the draw time is reduced by 50% :D wow! before I got like 0.005 seconds and now 0.0006 seconds ;P niice :D public BufferedImage scaleImage(BufferedImage original, int width, int height) {
@@RisingCookie13 You are a lifesaver! I still don't get why this isn't a problem for RyiSnow, I get exactly the same problem as you and your solution fixed it. Do you know why this method works for us but not his? I also noticed in some earlier videos as well that I had to make a few changes, it seems like it doesn't work exactly the same in IntelliJ which I am using. Is this the case for you as well?
@@alvins5054 heyy Alvin! :) I'm so happy I could help you :D Yes you are right, I was using intellij! he is using eclipse,.. but at my new workplace right now, I need to use eclipse too.. its often such a pain in the ass XD but it has one advantage.. it's open source and free - with all it's many functions.. and not many can affort or want to pay intellij ultimate, so companies use eclipse.. I can't imagen another reason.. because intellij is soo nice to use and prettier ^^` x) maybe eclipse works different here, and has some more possibilities...(?) are you also not using ultimate? :P
@@lauradauner3984 Hi! No I'm not using ultimate, just the good old Community Edition :) Thanks for the help again, just think it's strange that it works in Elipse but not in IntelliJ and I would love to understand why this is the case.
as soon as i do the objectives it gives me Exception in thread "main" java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358) at entity.Player.setup(Player.java:74) at entity.Player.getPlayerImage(Player.java:55) at entity.Player.(Player.java:41) at main.GamePanel.(GamePanel.java:40) at main.Main.main(Main.java:15) but if i remove the objective debugs it works
i had everything working nice, but now i get the null image problem. i did some reading and found that i could have problems with my the permission with my resource files. I change the code to use: tile[i].image = ImageIO.read(new File("/tiles/" + imageName + ".png")); and this works but tile[i].image = ImageIO.read(getClass().getResourceAsStream("/tiles/" + imageName + ".png")); does not. I am wondering if resource files locations can get messed up? I have tried to import the files again but that did not work. I had this problem also with the text file for the map. Can anyone help? public void setup(int i, String imageName, boolean collision) { UtilityTool uTool = new UtilityTool(); try { tile[i].image = ImageIO.read(getClass().getResourceAsStream("/tiles/" + imageName + ".png")); tile[i].image = uTool.scaleImage(tile[i].image, gp.tileSize, gp.tileSize); tile[i].collision = collision; }catch(IOException e) { e.fillInStackTrace(); } }
Hey Ryi! So this is a dummy question but I have to ask! How can I add the background image into my game. I tried copying at pasting this “g2.drawImage” but I want to just paste the normal sized image it’s like screen sized and I’m using it for a random encounter!! Please send help! すいません、いつもお世話になります! _(┐「ε:)_
Thank you so much!! Where do you recommend making the class? In UI? Or do I not need the class just draw “g2.drawImage(screenSizeX, screenSizeY); Basically I’m a noob. I can draw a String or image but simply how could I draw with the parameters of screenSize?
If anyone else is having troubles with a blank screen and "this.tile[tileNum]", check the getTitleImage method, that each line has a different index and that you didn't forget to initialize any tile
Hello Sir i am getting an error of following type in TileManager class what is a possible solution😅 -------------------------------------------------------- Exception in thread "main" java.lang.Error: Unresolved compilation problems: The type java.lang.IllegalArgumentException cannot be resolved. It is indirectly referenced from required .class files Unhandled exception type NumberFormatException at tile.TileManager.(TileManager.java:1) at main.GamePanel.(GamePanel.java:41) at main.Main.main(Main.java:13)
This is TileManager class ----------------------------------------- package tile; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import javax.imageio.ImageIO; import main.GamePanel; import main.UtilityTool; public class TileManager { GamePanel gp; public Tile[] tile; public int mapTileNum[][];
help! Exception in thread "main" java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356) at tile.TileManager.setup(TileManager.java:44) at tile.TileManager.getTileImage(TileManager.java:30) at tile.TileManager.(TileManager.java:25) at main.GamePanel.(GamePanel.java:29) at main.Main.main(Main.java:13)
Hey Ryi! Hope you're doing well, I've ran into a few errors but i don't really know how to fix them, here is what the errors say; Exception in thread "main" java.lang.IllegalArgumentException: input null ! at java.desktop/javax.imageio. Image10.read(ImageIO.java:1358) at tile. TileManager.setup(TileManager.java:49) at tile. TileManager.getTileImage (TileManager.java:34) at tile.TileManager.
Nevermind, I managed to fix it, it was just two tile names being misspelled, I had "grass" and "water" but my tiles were actually called "grass00" and "water00" I'm really dumb haha
Hi! I appreciate your work and your way of spreading knowledge to us. I've encountered a small problem after I instatiated the GamePanel into my objects: Exception in thread "main" java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358) at My2DGame/tile.TileManager.setup(TileManager.java:45) at My2DGame/tile.TileManager.getTileImage(TileManager.java:34) at My2DGame/tile.TileManager.(TileManager.java:25) at My2DGame/main.GamePanel.(GamePanel.java:34) at My2DGame/main.Main.main(Main.java:14) I've checked it, and... turns out I need not use the .png extension for the player object's pics in the setup methods... or so I thought... until I've found a typo ("earh" instead of "earth") So, yeah. It failed to find a certain "earh.png" while I intended the game to search for "earth.png" The first time I started watching your videos was the time I started to like Java. Kudos to you!
Hello! I am having an issue with when i try to call the setup method with setup(0, "stone", false); game wont start at all, if I go back to the original method it works fine though, I am receiving these errors and im not sure why Exception in thread "main" java.lang.IllegalArgumentException: input == null! at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356) at tile.TileManager.setup(TileManager.java:48) at tile.TileManager.getTileImage(TileManager.java:33) at tile.TileManager.(TileManager.java:28) at main.GamePanel.(GamePanel.java:36) at main.main.main(main.java:14) I have triple checked everything and I cant for the life of me figure out whats going wrong when I call try the setup method using the new code
HA for anyone running into this issue i fixed it by adding "this" to getClass in the image reader so it looks like this tile[index].image = ImageIO.read(this.getClass().getResourceAsStream("/tiles/" +imageName + ".png"));
"For now it's not a big difference"
I mean, i am almost a complete illiterate programming wise, but you decreased the rendering time by around a 30%, correct me if i am wrong.
Anyway, i really like dev videos like this one. I feel that a lot of pc games nowadays come out without proper optimizations. And somehow, people has grown used to run games by brute force regardless of wether it should or it shouldn't take so many resources.
I encourage you to do more videos about optimizations like this one! And looking forward for the next part!
I was thinking "Man, this turned out to be a pretty boring episode" haha so I'm glad you enjoyed it!
Once we add everything in the second half, the program takes about 3,000,000 nanoseconds to draw without pre-scaling (in my environment at least) and we can reduce it to about 1,500,000 nanoseconds with this method so the more we add stuff, the more this kind of optimization becomes effective ;)
For me it ended up making it 284% faster
*If your image background is turning black, or your images are turning white when drawing, i've found the solution* --> When RyiSnow was writing the UtilityTool class, he put the image type in the scaleImage method as a random (don't know if "random" is the right word) one -->(BufferedImage scaledImage = new BufferedImage(width, height, original.getType()), "original.getType()" is what I mean, it will return an int which is the imageType chosen, and can vary), I don't really know why but it gives that error. *The solution is to substitute "original.getType()" for "2"* (specify the imageType just for imageType 2). it will look like this "BufferedImage scaledImage = new BufferedImage(width, height, 2);". It worked for me so it might as well work for you, I hope, and sorry if my words are very hard to understand lol.
bro u are a legend
Thank you so much! This really helped!
Man, you're insane! Huge thanks🏅 Cuz, actually its really broke my head. Really cool!
Thank you very much! ❤
you are my god
Man I appreciate your effort in every video. I hope you enjoy what you make as much as I learn from you. THANKS!
Yes, I'm enjoying this and you guys' comments are giving me extra motivation :)
Really cool to see how to optimised graphics functions. Best JAVA 2D tutorials on RUclips.
Great tutorial, great explanation. I am asking for more such material!
I hated how necassary this was. yea you could say "man this as boring"...but I feel prepared for whats next. loved it and your explanations as always!
looking at the playlist is awe inspiring. I cannot wait to learn how to transition maps and a trade system. Those two things are going to REALLY make this game feel like it gained some legs
Happy to see people watching these videos too nowadays
@alex_tremo255 i have plans and I think watching Pirate software really got me going to search out for where to learn. This guy deserves a ton more love for explaining and showing what hes doing
IN CASE ANYONE ARE EXPERIENCING IMAGES TURNING BLACK AFTER RESIZING.
I made my new tiles in PhotoPea(seems like the software is somehow related) and for some reason the images wont scale properly in Java code.
I remade my tiles with Piskel, now everything works fine..
I had the same issue in episode 18 when I tried creating my own Heart pixel images in PhotoPea. I think it compressed the image files alot upon exporting or something.
Really love your work man!
Quick tip: instead of writing “if (checkDrawTime == true){checkDrawTime = false}” you can just write “checkDrawTime = !checkDrawTime”
it's not really the same cause with your metod you "flip" the value everytime, while with the if statement you flip it only if it is true.
@@hawkale140 it was: if else... so yeah, this was intented to work as a flip and tyson was correct.
My performance decreased after these additions, and I don't know why. It went from around 9.000.000 on average to over 11.000.000.
Also, you didn't remove the scaling from the draw() method of the SuperObject class
I thought that was just me. My draw time doubled after the new code.
you can chage all if(someVariable == true) to if(someVariable) and if(someVariable == false) to if(!someVariable).
Bruh i love your videos!
You should do turn based jrpgs next
I am enjoying this series
Thanks you so much for this video!
at min 3:20, if you want to control the variable based on previous state and set it to opposite, you can simply write:
checkDrawTime = !checkDrawTime
Another thing I see you write everywhere is:
if (condition == true) or if(condition == false)
This is not necessary since the if statement evaluates to true or false the expression inside the parenthesis, you can simply write:
if (condition) or if (!condition)
Is there any particular reason "UtilityTool" needs to be instantiated? Couldn't you just make "scaleImage" a static method?
Yeah, thats what i also thought, i think it is much better to treat this class like a Math class
Nice. Thanks for clear explanation.
Just curious, have you made android games before?
Yes I have and I also made a tutorial series.
Thank you! you`re awesome!
I have a question. Everything works fine on my end, nothing to do with bugfixing or debugging. But, wouldn't it be a good idea to implement the setup method in the Entity class and call it from Player class? I think it would work better if you also want to load sprites for mobs, NPCs or other entities. Also, can't we overload the method? We can have an index one and a non-index one. Lmk if its a good idea pls!
The SuperObject class is parent class of all the OBJ_subclasses. And even the draw(...)-Method of SuperObject class has GamePanel gp as parameter. We should let inherit that gp for the subclasses instead of giving every single subclass that reference by hand. I tried to organize it myself, but then there is the AssetSetter class too, which is acting with setObject(). This three classes we should handle different. And even I think we should implement a single GameObject class for all game objects, including Entity. Would be really fine if you reorganize these classes, cause I will do definitely some failures.^^ 😉😉😉😉
i just used JOGL for that, its 3-4 times faster, and its even faster if you write proper wrapper for its drawing functions for some reason
Hmm, I really didn't like the fact the object size was tied to tile size, so I created a separate final int in SuperObject called OBJECT_DEFAULT_SIZE. That way I didn't have to put gamepanel in the objects, which felt weird and unintuitive to me. I feel like maybe final values that are just set and can never be changed should maybe be defined elsewhere, like in settings or something, and then load all those values at once. So you have a Settings class or something, and on startup, Settings reads settings off a file and decides stuff like tile size and object size.
I don't know if that's necessarily the best idea, but it feels weird going back to gamepanel for everything.
Correct me if i'm wrong, but i think you made a mistake. In SuperObject class you are still scaling the images and in every object class it seems like you forgot actually set the image to scaled image. You just called the scaleImage function and didn't do anythink with the BufferedImage it returned.
I noticed it too, i mean, shouldn't he have coded " image = uTool.scaleImage(image, gp.tileSize, gp.tileSize); " ?
@@MrCricriboy Yes he should have. Doing that in all object files plus removing the gp.tileSize, gp.tileSize out of the g2.draw image line in the SuperObject class should fix it.
@RyiSnow
May i ask a Question?
Do we Really need to display the drawtime on screen??
Cant we just code the draw time and make the game smooth but just not display it??
if its necessary then alright
In case anyone was getting the vertical black lines in their game when they followed the tutorial, go into your UtilityTool class, find the BufferedImage method, and change
g2.drawImage(original, 3, 0, width, height, null);
to
g2.drawImage(original, 0, 0, width, height, null); //x default 3. setting it to 0 removed the gaps
I'm a little confused as to why you declaring Gamepanel gp and this.gp = gp in every object. Since we're passing gp as a parameter when we call our objects, wouldn't the public OBJ_ObjectName(GamePanel gp), as well as the uTool code, be enough??
the best of the best
Before I had 1000000, and now i have 100000. THANKS
Help.... I still get black screen... I created my tiles with piskel, idk what to do...
I followed all the video and I have a problem: the scaleImage method provides an exception, Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0. I just have no idea on how to solve it, do anyone knows what could be?
18:53 the "uTool.scaleImage(image, gp.tileSize, gp.tileSize);" for the OBJ_Key etc classes doesnt appear to do anything since the SuperObject() class draw() method still uses "g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);" and if you remove "gp.tileSize, gp.tileSize" from g2.drawImage(), the scaling never happens even though uTool.scaleImage is implemented in the OBJ_Key() class. You just end up with really tiny objects drawn on the map in that case. I dont know what the solution is.
What a genious
To make the setup sequence a bit more versatile one could simply add in the extension as a String. This way if the file was a jpeg, png, tiff or other file you could just use that specific version to access it. Also you kind of forgot to set the objects images to the scaled image after scaling them. Also you forgot to remove the width and height from the draw image class itself since we have already scaled them before the images get rendered.
is there any way to change the collision area of the tiles using this method?
I hope you're having a great time. i ran into an issue when i'm rendering this way, my player is turning black and white when i renders this way, would you know why this would happen?
I don't know exactly why this is happening, but after applying these changes my player character is now tiny. I've checked both the Util and Player classes, and both are identical to your code. Any idea on why this happens?
Can I see your Player class?
@@RyiSnow Well I checked every line of code and I found the error. I called the scaleImage method but didn't actually set the image equal to it. So it wasn't actually scaling the image. Thanks for your time and keep up the great work!
@@tomatosoup1759 can you help me with same problem? all my pictures are tiny, and all in tutorial identical to my code
@@КсюшаАртси make sure you didn’t do what I did and set the image equal to the scaleImage method instead of just calling it. I haven’t gone back to this tutorial in a while so I don’t remember anything else, hopefully that fixes your problem
Thank you!
I don't know what happened, but when I start the game, "DrawTime" is already being shown on the screen and the shortcut Key doesn't work, not even to take it off the screen. Can you help me?
Hey!, Why do we use Java 12 and not 8, or 18/19 is it because its the earliest versions with the features we need or something else?
The speed of the character while walking I guess increased by 200% after applying although I didn't change the speed amount. I don't know why.
Maybe you have another size of your sprites and this is why player is moving faster. We change render style now, maybe also it changes for you the size. Greetings!
@@kamilgren8117 Thank you for your reply. I didn't follow the improve rendering step or I skip that and continue the tutorial. So far my modified game is still good. Hehe.
In objects door, etc.. you forgot to set resized image
bufferedImage = utilityTool.scaleImage(bufferedImage, gamePanel.tileSize, gamePanel.tileSize);
and in SuperObject draw remove resizing.
This!
Loving the tutorial series dude! Unfortunately after following this video, I get the following error when trying to run the game:
Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0
at java.awt.image.BufferedImage.(BufferedImage.java:501)
at main.UtilityTool.scaleImage(UtilityTool.java:9)
at tile.TileManager.setup(TileManager.java:46)
at tile.TileManager.getTileImage(TileManager.java:30)
at tile.TileManager.(TileManager.java:24)
at main.GamePanel.(GamePanel.java:32)
at main.Main.main(Main.java:13)
Useful lines of code to know:
TileManager.setup(TileManager.java:46) is this line:
tile[index].image = uTool.scaleImage(tile[index].image, gp.tileSize, gp.tileSize);
UtilityTool.scaleImage(UtilityTool.java:9) is this line:
BufferedImage scaledImage = new BufferedImage(width,height,original.getType());
After debugging and finding the source of problem, it seems as my code fires the error just after running the first line in the getTileImage() method from the TitleManager class:
setup(0,"grass1",false);
I think the program has trouble finding the image type from an int but I could be way off. I think the problem is either coming from the UtilityTool or TileManager class, just for a sense of direction. Any pointers or help would be massively appreciated as I want to carry on with these tutorials! :D
Having the same issue, did you ever find a fix?
@RyiSnow ,Can you please explain me why my drawtime has moments where it changes from 5milion to 14 million all of the sudden and black lines appear between my tiles?RyiSnow
when I do everything according to the tutorial, it doesn’t work out for me, everything remains 16 x 16 px. Can you help me? plz
after this episode, whenever my character moves right or up a black box flashes around the player icon :( any idea what could be causing this?
I did everything but the passed time is still the same ranging from 700k to 1.1mil before and after the implementation.. is that ok?
I noticed that if you implemnts the stopping camera at the edges of the map when you at the adges the time to draw is x10 than the time to draw when you are in the middle let me know what do you think about that and if you have idea to optimaze this too
I couldn't seem to get any improvements with this. I'm sure I messed up the implementation somewhere. I don't suppose you have idea what I could have missed that would cause it to not actually improve the time?
my plyer sprite now has a solid black box behind him after scaling, everything else works fine though, any ideas?
Thanks!
It improved mine by 3x, but I had to go through mental distress to do it.
Everything is fine but I have a problem. In my drawTime it is showing me a number like this 259543180941500 and it still increasing not just jumping around this number. What happening to my code when everythink what I done is like your code? Thank you for any answer.
I have a solution guys but I don't understand why on video it is working and in my situation didn't, So solution was I must put drawStart out of if statement because it never write time into this value. After then I have everything working good.
Man i have this problem Exception in thread "main" java.lang.IllegalArgumentException: input == null! , i don't know what to do i have been searching for help on the internet but found nothing.
image = ImageIO.read(getClass().getResourceAsStream("/player/" + imageName + ".png"));
The problem was ths .png was " .png" but you can't have the space between.
Question I did everything and it works but when I turn it into an .jar file it doesn't BUT when I use the old image rendering system it works. is there somethings wrong with my code or the whole new rendering system?
Jar is case-sensitive while IDE is not so I think checking the file names and the paths of the newly added images is a good start.
Thank you very much for the lesson. It turns out very cool. I'm trying to make a game for a college course project. But I don’t know how to zoom the camera, for example, if I want, for example, when I turn on a certain function in the menu or press a key, my camera will zoom in twice, for example... Guys, if you know how to do this using the example of this cool game, please share a source or a hint if it’s not difficult for you.
Thanks :)
After this code the game screen is black, I can move myself and see the objects but my player and tiles are black. Help me. pls.
Try to create a new sprite. Use pixels for example. I got that problem too, and after replacing my sprites it works fine
Cool but suggest better names for vars
After finishing this part of the tutorial, all my collision checking in not happening. Is there a quick way to check what I did wrong?
in "getTileImage", check that you have set "true" for the water, the wall and the trees
@@alexandradesplan357 saved me lol, thank you!
I keep getting errors for g2.drawImage(tile[tileNum].image, screenX, screenY, null);
Cannot read field "image" because "this.tile[tileNum]" is null
NEVERMIND I FOUND IT IT WAS JUST THE INDEX WAS input WRONG. wow I spent three hours debugging just for a single number off. still awesome tutorial
after this video my character has some kind of black background, i wrote the code very well so i don't understand what the problem is, any help?
I had this same problem, please somebody help us!
same
Can you make a guide on how to implement opponents/mobs?
Monsters will be included in later part of this tutorial :)
@@RyiSnow Yes!! Exactly what I was looking for. Will you incorporate random mob movement and such?
Not planning to go too deep but we will implement a simple monster AI so they move randomly.
@@RyiSnow Ok Great!
Please anyone help I'm getting the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot read field "image" because "this.tile[tileNum]" is null
I don't know what I did wrong but my games screen went blank an didn't load anything and couldn't close and then I could hear my laptop struggling to comprehend the stupidity of whatever mistake I made while the fans kept getting louder and louder... so I'm sure that's a good sign😂
after making the modification my tiles turned white, how crazy.
pls help!
that when you changed the tiles for other things they worked (images) they must have noticed
Sorry I don't understand what you mean. Can you describe the situation in more detail (the error message you are getting, which line is causing it, when the issue started etc.)?
Hey my character is now randomly blinking is that normal?
Turns out there was a typo in one line, that I missed.
🥰🥰🥰
Hi! Can you please explain me why my drawtime has moments where it changes from 100000 to 14 million all of the sudden and black lines appear between my tiles?
Comment for algorithm
I think my performance got worse actually
Is it normal that my drawTime is 0 and 100?? HAAAHAAHAHAAH
Hello. I am getting the below mentioned error after following this video. If anyone can help me out with this it will be very helpful since i want to continue the playlist and complete this game. thank you.
Error:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356)
at tile.TileManager.setup(TileManager.java:48)
at tile.TileManager.getTileImage(TileManager.java:34)
at tile.TileManager.(TileManager.java:28)
at main.GamePanel.(GamePanel.java:36)
at main.main.main(main.java:13)
The program is failing to read the image file. Most likely you passed the wrong file name to the setup method.
@@RyiSnow oops! One small silly mistake overlooked. Thank you very much!
@@soumiksensharma9338 Was it ".getClassLoader()" ? I ran into that problem as well. Same errors.
Can someone maybe help? What I did wrong?^^'
I get this error message:
"Exception in thread "main" java.lang.IllegalArgumentException: Unknown image type 0
at java.desktop/java.awt.image.BufferedImage.(BufferedImage.java:501)
at main.UtilityTool.scaleImage(UtilityTool.java:10)
at tile.TileManager.setup(TileManager.java:96)
at tile.TileManager.getTileImage(TileManager.java:36)
at tile.TileManager.(TileManager.java:28)
at main.GamePanel.(GamePanel.java:33)
at main.Main.main(Main.java:19)"
ooookay, I solved it xD hahaa finally can move on :P (my changed code of the UtilityTool-method is right below, for anyone having the same issue :)) Btw, the draw time is reduced by 50% :D wow! before I got like 0.005 seconds and now 0.0006 seconds ;P niice :D
public BufferedImage scaleImage(BufferedImage original, int width, int height) {
GraphicsConfiguration gc = original.createGraphics().getDeviceConfiguration();
BufferedImage scaledImage = gc.createCompatibleImage(width, height, BufferedImage.BITMASK);
Graphics2D g2 = scaledImage.createGraphics();
g2.drawImage(original, 0, 0, width, height, null);
g2.dispose();
return scaledImage;
}
@@RisingCookie13 You are a lifesaver!
I still don't get why this isn't a problem for RyiSnow, I get exactly the same problem as you and your solution fixed it. Do you know why this method works for us but not his?
I also noticed in some earlier videos as well that I had to make a few changes, it seems like it doesn't work exactly the same in IntelliJ which I am using. Is this the case for you as well?
@@alvins5054 heyy Alvin! :) I'm so happy I could help you :D Yes you are right, I was using intellij! he is using eclipse,.. but at my new workplace right now, I need to use eclipse too.. its often such a pain in the ass XD but it has one advantage.. it's open source and free - with all it's many functions.. and not many can affort or want to pay intellij ultimate, so companies use eclipse.. I can't imagen another reason.. because intellij is soo nice to use and prettier ^^` x)
maybe eclipse works different here, and has some more possibilities...(?)
are you also not using ultimate? :P
@@lauradauner3984 Hi!
No I'm not using ultimate, just the good old Community Edition :)
Thanks for the help again, just think it's strange that it works in Elipse but not in IntelliJ and I would love to understand why this is the case.
im having the same problem like that idk how to solve it can someone help me?
as soon as i do the objectives it gives me
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358)
at entity.Player.setup(Player.java:74)
at entity.Player.getPlayerImage(Player.java:55)
at entity.Player.(Player.java:41)
at main.GamePanel.(GamePanel.java:40)
at main.Main.main(Main.java:15)
but if i remove the objective debugs it works
i had everything working nice, but now i get the null image problem. i did some reading and found that i could have problems with my the permission with my resource files. I change the code to use:
tile[i].image = ImageIO.read(new File("/tiles/" + imageName + ".png")); and this works but
tile[i].image = ImageIO.read(getClass().getResourceAsStream("/tiles/" + imageName + ".png")); does not. I am wondering if resource files locations can get messed up? I have tried to import the files again but that did not work. I had this problem also with the text file for the map. Can anyone help?
public void setup(int i, String imageName, boolean collision) {
UtilityTool uTool = new UtilityTool();
try {
tile[i].image = ImageIO.read(getClass().getResourceAsStream("/tiles/" + imageName + ".png"));
tile[i].image = uTool.scaleImage(tile[i].image, gp.tileSize, gp.tileSize);
tile[i].collision = collision;
}catch(IOException e) {
e.fillInStackTrace();
}
}
i fixed it.... ended up being the res folder not a source folder and i forgot to add the tile[i] = new Tile();
Hey Ryi! So this is a dummy question but I have to ask!
How can I add the background image into my game.
I tried copying at pasting this “g2.drawImage” but I want to just paste the normal sized image it’s like screen sized and I’m using it for a random encounter!!
Please send help!
すいません、いつもお世話になります!
_(┐「ε:)_
You can do that by scaling the image to the screen size.
Thank you so much!!
Where do you recommend making the class? In UI? Or do I not need the class just draw “g2.drawImage(screenSizeX, screenSizeY);
Basically I’m a noob. I can draw a String or image but simply how could I draw with the parameters of screenSize?
If anyone else is having troubles with a blank screen and "this.tile[tileNum]", check the getTitleImage method, that each line has a different index and that you didn't forget to initialize any tile
Hello Sir i am getting an error of following type in TileManager class
what is a possible solution😅
--------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type java.lang.IllegalArgumentException cannot be resolved. It is indirectly referenced from required .class files
Unhandled exception type NumberFormatException
at tile.TileManager.(TileManager.java:1)
at main.GamePanel.(GamePanel.java:41)
at main.Main.main(Main.java:13)
This is TileManager class
-----------------------------------------
package tile;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.imageio.ImageIO;
import main.GamePanel;
import main.UtilityTool;
public class TileManager {
GamePanel gp;
public Tile[] tile;
public int mapTileNum[][];
public TileManager(GamePanel gp) {
this.gp=gp;
tile=new Tile[10];
mapTileNum=new int[gp.maxWorldCol][gp.maxWorldRow];
getTileImage();
loadMap("/maps/world01.txt");
}
public void getTileImage() {
setUp(0,"grass",false);
setUp(1,"wall",true);
setUp(2,"water",true);
setUp(3,"earth",false);
setUp(4,"tree",true);
setUp(5,"sand",false);
}
public void setUp(int index,String imageName,boolean collision) {
UtilityTool uTool=new UtilityTool();
try {
tile[index]=new Tile();
tile[index].image=ImageIO.read(getClass().getResourceAsStream("/tiles/" + imageName + ".png"));
tile[index].image=uTool.scaleImage(tile[index].image, gp.tileSize,gp.tileSize);
tile[index].collision=collision;
}catch(IOException e) {
e.printStackTrace();
}
}
public void loadMap(String filePath) {
try {
InputStream is=getClass().getResourceAsStream(filePath);
BufferedReader br=new BufferedReader(new InputStreamReader(is));
int col=0;
int row=0;
while(col
@@mohanoli5882 man seriously just posted his hole class
help!
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356)
at tile.TileManager.setup(TileManager.java:44)
at tile.TileManager.getTileImage(TileManager.java:30)
at tile.TileManager.(TileManager.java:25)
at main.GamePanel.(GamePanel.java:29)
at main.Main.main(Main.java:13)
SDK problem
I have the same problem.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
What's it?
Did you fix it I have the same error
@@wizco4443 yes, i did
The error stay in the number of tiles
Hey Ryi! Hope you're doing well, I've ran into a few errors but i don't really know how to fix them, here is what the errors say;
Exception in thread "main" java.lang.IllegalArgumentException: input null !
at java.desktop/javax.imageio. Image10.read(ImageIO.java:1358)
at tile.
TileManager.setup(TileManager.java:49)
at tile. TileManager.getTileImage (TileManager.java:34)
at tile.TileManager.
Nevermind, I managed to fix it, it was just two tile names being misspelled, I had "grass" and "water" but my tiles were actually called "grass00" and "water00"
I'm really dumb haha
Hi!
I appreciate your work and your way of spreading knowledge to us.
I've encountered a small problem after I instatiated the GamePanel into my objects:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358)
at My2DGame/tile.TileManager.setup(TileManager.java:45)
at My2DGame/tile.TileManager.getTileImage(TileManager.java:34)
at My2DGame/tile.TileManager.(TileManager.java:25)
at My2DGame/main.GamePanel.(GamePanel.java:34)
at My2DGame/main.Main.main(Main.java:14)
I've checked it, and... turns out I need not use the .png extension for the player object's pics in the setup methods... or so I thought... until I've found a typo ("earh" instead of "earth")
So, yeah. It failed to find a certain "earh.png" while I intended the game to search for "earth.png"
The first time I started watching your videos was the time I started to like Java. Kudos to you!
Hello! I am having an issue with when i try to call the setup method with setup(0, "stone", false); game wont start at all, if I go back to the original method it works fine though, I am receiving these errors and im not sure why
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356)
at tile.TileManager.setup(TileManager.java:48)
at tile.TileManager.getTileImage(TileManager.java:33)
at tile.TileManager.(TileManager.java:28)
at main.GamePanel.(GamePanel.java:36)
at main.main.main(main.java:14)
I have triple checked everything and I cant for the life of me figure out whats going wrong when I call try the setup method using the new code
any help from anyone would be greatly appreciated
HA for anyone running into this issue i fixed it by adding "this" to getClass in the image reader so it looks like this
tile[index].image = ImageIO.read(this.getClass().getResourceAsStream("/tiles/" +imageName + ".png"));
nevermind, I had quotation marks in the wrong place, I got everything working but it does seem it made draw time slower
Can you tell me how you solve the problem?
Nvm i got it... I just misspell my setUp to setup...