Improving Rendering Performance - How to Make a 2D Game in Java #11

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 165

  • @sorcerian_bootleg7112
    @sorcerian_bootleg7112 2 года назад +43

    "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!

    • @RyiSnow
      @RyiSnow  2 года назад +23

      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 ;)

    • @Duarte0105
      @Duarte0105 Год назад +4

      For me it ended up making it 284% faster

  • @hiswar370
    @hiswar370 Год назад +28

    *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.

    • @kiru11
      @kiru11 Год назад +4

      bro u are a legend

    • @Bozzyperson
      @Bozzyperson Год назад +3

      Thank you so much! This really helped!

    • @dezik5535
      @dezik5535 Год назад +2

      Man, you're insane! Huge thanks🏅 Cuz, actually its really broke my head. Really cool!

    • @kiki-creeper5535
      @kiki-creeper5535 Год назад +2

      Thank you very much! ❤

    • @SuzuKanae
      @SuzuKanae Год назад +2

      you are my god

  • @funkychicken3584
    @funkychicken3584 2 года назад +23

    Man I appreciate your effort in every video. I hope you enjoy what you make as much as I learn from you. THANKS!

    • @RyiSnow
      @RyiSnow  2 года назад +11

      Yes, I'm enjoying this and you guys' comments are giving me extra motivation :)

  • @mikemazanetz4183
    @mikemazanetz4183 7 месяцев назад

    Really cool to see how to optimised graphics functions. Best JAVA 2D tutorials on RUclips.

  • @adamfaciszewski7197
    @adamfaciszewski7197 2 года назад +2

    Great tutorial, great explanation. I am asking for more such material!

  • @Mypremiumacct
    @Mypremiumacct 3 месяца назад +1

    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!

    • @Mypremiumacct
      @Mypremiumacct 3 месяца назад +1

      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
      @alex_tremo255 2 месяца назад +1

      Happy to see people watching these videos too nowadays

    • @Mypremiumacct
      @Mypremiumacct 2 месяца назад +1

      @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

  • @paaulsens6086
    @paaulsens6086 2 года назад +12

    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.

  • @StretchyTime
    @StretchyTime 2 года назад +1

    Really love your work man!

  • @tysonchicken9232
    @tysonchicken9232 2 года назад +3

    Quick tip: instead of writing “if (checkDrawTime == true){checkDrawTime = false}” you can just write “checkDrawTime = !checkDrawTime”

    • @hawkale140
      @hawkale140 2 года назад +1

      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.

    • @tofame4291
      @tofame4291 10 месяцев назад

      @@hawkale140 it was: if else... so yeah, this was intented to work as a flip and tyson was correct.

  • @upperplus7953
    @upperplus7953 Год назад +12

    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

    • @AlexanderHL1919
      @AlexanderHL1919 5 месяцев назад

      I thought that was just me. My draw time doubled after the new code.

  • @mastergamer4335
    @mastergamer4335 2 года назад +8

    you can chage all if(someVariable == true) to if(someVariable) and if(someVariable == false) to if(!someVariable).

  • @VernorsDoctor
    @VernorsDoctor 11 дней назад

    Bruh i love your videos!
    You should do turn based jrpgs next

  • @prizepig
    @prizepig 2 года назад +1

    I am enjoying this series

  • @NikitaBomba112
    @NikitaBomba112 Год назад +1

    Thanks you so much for this video!

  • @0ShinigamiDN0
    @0ShinigamiDN0 Месяц назад

    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)

  • @dgarrard100
    @dgarrard100 Год назад +4

    Is there any particular reason "UtilityTool" needs to be instantiated? Couldn't you just make "scaleImage" a static method?

    • @karaczan5839
      @karaczan5839 6 месяцев назад

      Yeah, thats what i also thought, i think it is much better to treat this class like a Math class

  • @agent-33
    @agent-33 2 года назад +2

    Nice. Thanks for clear explanation.
    Just curious, have you made android games before?

    • @RyiSnow
      @RyiSnow  2 года назад +4

      Yes I have and I also made a tutorial series.

  • @dariomiguel3460
    @dariomiguel3460 Год назад +1

    Thank you! you`re awesome!

  • @kingrulez5268
    @kingrulez5268 Год назад +3

    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!

  • @ParalyticAngel
    @ParalyticAngel 6 месяцев назад

    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.^^ 😉😉😉😉

  • @ІлляТкачов
    @ІлляТкачов Год назад +1

    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

  • @freshie94
    @freshie94 10 месяцев назад +1

    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.

  • @progress2171
    @progress2171 Год назад +2

    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
      @MrCricriboy 10 месяцев назад +1

      I noticed it too, i mean, shouldn't he have coded " image = uTool.scaleImage(image, gp.tileSize, gp.tileSize); " ?

    • @nathanc11
      @nathanc11 8 месяцев назад

      @@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.

  • @ackoly_dude4495
    @ackoly_dude4495 Месяц назад

    @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

  • @happyburger23
    @happyburger23 Год назад +1

    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

  • @kentcampbell122
    @kentcampbell122 Месяц назад

    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??

  • @eld4j
    @eld4j Год назад +1

    the best of the best

  • @Julson_PL
    @Julson_PL Год назад

    Before I had 1000000, and now i have 100000. THANKS

  • @Klomerastickles-37onBloodbath-
    @Klomerastickles-37onBloodbath- 3 месяца назад

    Help.... I still get black screen... I created my tiles with piskel, idk what to do...

  • @LoreSam
    @LoreSam 5 месяцев назад

    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?

  • @AlexanderHL1919
    @AlexanderHL1919 5 месяцев назад

    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.

  • @daryelcetz1410
    @daryelcetz1410 8 месяцев назад

    What a genious

  • @boltgreywing4562
    @boltgreywing4562 10 месяцев назад

    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.

  • @deliciouskromer3185
    @deliciouskromer3185 2 года назад +1

    is there any way to change the collision area of the tiles using this method?

  • @georgehaddad1810
    @georgehaddad1810 2 года назад +1

    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?

  • @tomatosoup1759
    @tomatosoup1759 2 года назад +2

    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
      @RyiSnow  2 года назад +1

      Can I see your Player class?

    • @tomatosoup1759
      @tomatosoup1759 2 года назад +2

      @@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!

    • @КсюшаАртси
      @КсюшаАртси Год назад +1

      @@tomatosoup1759 can you help me with same problem? all my pictures are tiny, and all in tutorial identical to my code

    • @tomatosoup1759
      @tomatosoup1759 Год назад

      @@КсюшаАртси 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

  • @rehunt9999
    @rehunt9999 Год назад

    Thank you!

  • @cueio7454
    @cueio7454 Год назад

    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?

  • @nicholasbrooks7349
    @nicholasbrooks7349 Год назад

    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?

  • @kimabram
    @kimabram Год назад +1

    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.

    • @kamilgren8117
      @kamilgren8117 Год назад +1

      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!

    • @kimabram
      @kimabram Год назад +1

      @@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.

  • @tapin13
    @tapin13 10 месяцев назад +1

    In objects door, etc.. you forgot to set resized image
    bufferedImage = utilityTool.scaleImage(bufferedImage, gamePanel.tileSize, gamePanel.tileSize);
    and in SuperObject draw remove resizing.

  • @SwooshFX
    @SwooshFX 2 года назад +4

    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

  • @КсюшаАртси
    @КсюшаАртси Год назад

    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

  • @0x_noot
    @0x_noot Год назад

    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?

  • @janrui2477
    @janrui2477 Год назад

    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?

  • @zach990il4
    @zach990il4 2 года назад

    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

  • @snarpking
    @snarpking 2 года назад

    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?

  • @reddeadrp8554
    @reddeadrp8554 2 года назад

    my plyer sprite now has a solid black box behind him after scaling, everything else works fine though, any ideas?

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks!

  • @rexroyulada6267
    @rexroyulada6267 5 месяцев назад

    It improved mine by 3x, but I had to go through mental distress to do it.

  • @MrDiginalt
    @MrDiginalt Год назад

    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.

    • @MrDiginalt
      @MrDiginalt Год назад

      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.

  • @panicuros7301
    @panicuros7301 2 года назад +1

    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.

    • @panicuros7301
      @panicuros7301 2 года назад

      image = ImageIO.read(getClass().getResourceAsStream("/player/" + imageName + ".png"));
      The problem was ths .png was " .png" but you can't have the space between.

  • @ttv_dark_scorpion
    @ttv_dark_scorpion Год назад

    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?

    • @RyiSnow
      @RyiSnow  Год назад

      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.

  • @angeldust2659
    @angeldust2659 7 месяцев назад

    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.

  • @cedricsahaghian1605
    @cedricsahaghian1605 Год назад

    Thanks :)

  • @helioktt
    @helioktt 2 года назад

    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.

    • @mamapuci
      @mamapuci 2 года назад +1

      Try to create a new sprite. Use pixels for example. I got that problem too, and after replacing my sprites it works fine

  • @Kenbomp
    @Kenbomp 3 месяца назад

    Cool but suggest better names for vars

  • @RandomHandle-r2q
    @RandomHandle-r2q 2 года назад

    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?

    • @alexandradesplan357
      @alexandradesplan357 2 года назад +1

      in "getTileImage", check that you have set "true" for the water, the wall and the trees

    • @abikyoukan2
      @abikyoukan2 Год назад

      @@alexandradesplan357 saved me lol, thank you!

  • @woodswoody5553
    @woodswoody5553 2 года назад

    I keep getting errors for g2.drawImage(tile[tileNum].image, screenX, screenY, null);

    • @woodswoody5553
      @woodswoody5553 2 года назад

      Cannot read field "image" because "this.tile[tileNum]" is null

    • @woodswoody5553
      @woodswoody5553 2 года назад

      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

  • @Denis-yv5lk
    @Denis-yv5lk 2 года назад

    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?

  • @adamfaciszewski7197
    @adamfaciszewski7197 2 года назад +1

    Can you make a guide on how to implement opponents/mobs?

    • @RyiSnow
      @RyiSnow  2 года назад +3

      Monsters will be included in later part of this tutorial :)

    • @bluethemcguy4430
      @bluethemcguy4430 2 года назад +1

      @@RyiSnow Yes!! Exactly what I was looking for. Will you incorporate random mob movement and such?

    • @RyiSnow
      @RyiSnow  2 года назад +3

      Not planning to go too deep but we will implement a simple monster AI so they move randomly.

    • @bluethemcguy4430
      @bluethemcguy4430 2 года назад +1

      @@RyiSnow Ok Great!

  • @wizco4443
    @wizco4443 Год назад +1

    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

  • @sensei6strings782
    @sensei6strings782 20 дней назад

    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😂

  • @jordanealmeida5986
    @jordanealmeida5986 2 года назад +1

    after making the modification my tiles turned white, how crazy.

    • @jordanealmeida5986
      @jordanealmeida5986 2 года назад

      pls help!

    • @jordanealmeida5986
      @jordanealmeida5986 2 года назад

      that when you changed the tiles for other things they worked (images) they must have noticed

    • @RyiSnow
      @RyiSnow  2 года назад

      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.)?

  • @nicholasbrooks7349
    @nicholasbrooks7349 Год назад

    Hey my character is now randomly blinking is that normal?

    • @nicholasbrooks7349
      @nicholasbrooks7349 Год назад +1

      Turns out there was a typo in one line, that I missed.

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

    🥰🥰🥰

  • @victorteslaru6960
    @victorteslaru6960 2 года назад

    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?

  • @jamesconwell2767
    @jamesconwell2767 2 года назад

    Comment for algorithm

  • @natzos6372
    @natzos6372 Год назад

    I think my performance got worse actually

  • @jayllonfan9182
    @jayllonfan9182 Год назад

    Is it normal that my drawTime is 0 and 100?? HAAAHAAHAHAAH

  • @soumiksensharma9338
    @soumiksensharma9338 2 года назад +2

    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)

    • @RyiSnow
      @RyiSnow  2 года назад +1

      The program is failing to read the image file. Most likely you passed the wrong file name to the setup method.

    • @soumiksensharma9338
      @soumiksensharma9338 2 года назад

      @@RyiSnow oops! One small silly mistake overlooked. Thank you very much!

    • @jamiebarr3118
      @jamiebarr3118 Год назад

      @@soumiksensharma9338 Was it ".getClassLoader()" ? I ran into that problem as well. Same errors.

  • @RisingCookie13
    @RisingCookie13 2 года назад +2

    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)"

    • @RisingCookie13
      @RisingCookie13 2 года назад +2

      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;
      }

    • @alvins5054
      @alvins5054 Год назад +1

      @@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?

    • @lauradauner3984
      @lauradauner3984 Год назад

      @@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

    • @alvins5054
      @alvins5054 Год назад +1

      @@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.

    • @akumakaito7730
      @akumakaito7730 Год назад

      im having the same problem like that idk how to solve it can someone help me?

  • @FinnishFlash17
    @FinnishFlash17 2 года назад

    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

  • @robertelovelace
    @robertelovelace 2 года назад

    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();
    }
    }

    • @robertelovelace
      @robertelovelace 2 года назад

      i fixed it.... ended up being the res folder not a source folder and i forgot to add the tile[i] = new Tile();

  • @2MSTennis
    @2MSTennis 2 года назад

    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!
    すいません、いつもお世話になります!
    _(┐「ε:)_

    • @RyiSnow
      @RyiSnow  2 года назад +1

      You can do that by scaling the image to the screen size.

    • @2MSTennis
      @2MSTennis 2 года назад

      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?

  • @moonpaper215
    @moonpaper215 2 года назад +2

    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

  • @mohanoli5882
    @mohanoli5882 Год назад

    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)

    • @mohanoli5882
      @mohanoli5882 Год назад

      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

    • @masterdob7600
      @masterdob7600 Год назад

      @@mohanoli5882 man seriously just posted his hole class

  • @FFl1s
    @FFl1s Год назад

    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)

  • @ghostofwar330
    @ghostofwar330 Год назад

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    What's it?

    • @wizco4443
      @wizco4443 Год назад

      Did you fix it I have the same error

    • @ghostofwar330
      @ghostofwar330 Год назад +1

      @@wizco4443 yes, i did
      The error stay in the number of tiles

  • @vVictorNos
    @vVictorNos 5 месяцев назад

    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.

    • @vVictorNos
      @vVictorNos 5 месяцев назад

      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

  • @tothpeter2296
    @tothpeter2296 Год назад +1

    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!

  • @maxrockatansky7446
    @maxrockatansky7446 Год назад

    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

    • @maxrockatansky7446
      @maxrockatansky7446 Год назад

      any help from anyone would be greatly appreciated

    • @maxrockatansky7446
      @maxrockatansky7446 Год назад

      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"));

    • @maxrockatansky7446
      @maxrockatansky7446 Год назад

      nevermind, I had quotation marks in the wrong place, I got everything working but it does seem it made draw time slower

    • @rodarcangel6655
      @rodarcangel6655 Год назад

      Can you tell me how you solve the problem?

    • @rodarcangel6655
      @rodarcangel6655 Год назад

      Nvm i got it... I just misspell my setUp to setup...