Map Screen and Minimap - How to Make a 2D Game in Java #47
In this video, we will implement a map screen and minimap function.
Guidelines for using Blue Boy Adventure's code and assets:
docs.google.com/document/d/1q...
Timestamps:
0:00 Introduction
0:23 Creating Map Class
5:22 Map Screen
14:45 Minimap
20:00 FINAL RESULT
#javatutorial #javagamedevelopment
Пікірлер: 39
Every time I get close to catching up, a new part releases! I look forward to following along with this one soon, too. Thank you!
I'm always so excited when i see a new video on your channel!
Thank you very much!!!
Exciting stuff!
As always nice and informative. Remember to dispose of Graphics2D object when you are done drawing to the BufferedImage(image), since you are creating Graphics2D g2 = image.createGraphics(), unless you dispose it, the resource will stay open. Its something that's easily forgotten.
@RyiSnow
Жыл бұрын
Oops you're right, I forgot about that. I will fix it in the next video. Thank you for pointing that out!
@TaariBarungsi
Жыл бұрын
@@RyiSnow No problem, I have an old computer, hence i always try to save memory as much as I can...
@deepseatrip
Жыл бұрын
@@TaariBarungsi I checked out my memory usage , I was using a 100x100 map and 32x32 tiles. It was pretty high and I have a nice computer , so I cut the map back to 50x50 and it helped a good amount. Ive now upped my tiles from 8x8 >16x16>32x32 and kind of wish I stayed at 16x16 lol but I love the crisp look of the 32x32 and Im too deep with over 200 tiles lol. One thing I noticed with my memory usage is that it consistently climbs and does not stop going up. I haven't really payed attention to this yet cause most the time I am not actually leaving the game running long but this would inevitably cause a crash. I am wondering if yours does the same thing, Ive added some random things like growable plants with a timer , so this probably something I have done or maybe it only significant to me cause tile/maps sizes and assets ive added in game.
@TaariBarungsi
Жыл бұрын
@@deepseatrip Since java uses CPU instead of GPU there is not much you can do about that, but i would recommend you to cut down over-creation of objects inside loops(for/while) and also if you can call on objects only when needed inside game-loop(update,render/draw). Instead of creating a new variable every loop-iteration, create the variables outside of the loop. That way you have a reference to the variable and can change its value instead of creating a new variable n-number of times inside a loop. Think about it for a moment, if you have a reference, you only need to access the memory location of that reference to make changes you don't request the allocation of new memory, but when you create a new variable inside a loop, you allocate memory for that variable and the garbage collector then deletes that variable at the end of a single-iteration and the loop may run for n-amount of times. The memory usage may not be that high for smaller projects but since there are images and drawing involved then surly you would begin to notice the lag. English isn't my language so i hope i explained it in a way that you could understand what i was trying to say.
@deepseatrip
Жыл бұрын
@@TaariBarungsi Thank you, you explained it great!
Wow cant wait to make my own game to enjoy
Thanks!
Amazing 👏
Hey, Ryisnow! I was looking back and wondered if it was possible to add interactive tiles on the map to avoid confusion. Thanks!
You are a hero my man
how do you include the other entities such as NPCs and objects into the map? because if I wanted to display a map with abundance of objects the map looks desolated when it only displays the tiles.
NICE!
Good man!
When will you implement the load game function? In the title screen video, you mentioned implementing load game
@RyiSnow
Жыл бұрын
It's coming pretty soon. I was waiting until all the data that we need to save/load are implemented in the program.
@64_bit_coding
Жыл бұрын
@@RyiSnow Ok. Thanks!
Hello, I need some help. I have a problem in KeyHandler, where I want the player to move. Can you solve my problem? Thank you
🥰🥰🥰
Can I request how to make tiles clickable with mouse 😁
So when I try to start the game after implementing the map for the first time, it crashes and sends this error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space I think it's cause my map is too large, cause when I shrink it down it works fine. Right now my map is 341x193. Do you know any way to fix this without changing the map size?
@cristofferostberg1297
8 ай бұрын
I am too getting this error with a 250x250 map.
@cristofferostberg1297
8 ай бұрын
You need to increase the heap memory in your JVM (only a plaster fix, i know, but its working temporarily, atleast) What IDE are you using? In IntelliJ = 1. Go to Help menu in IntelliJ 2. Scroll down to Edit Custom VM Options 3. Paste these lines (or update the existing, if they're lower than Xmx2024m) -Xms512m -Xmx2024m -XX:MaxPermSize=700m -XX:ReservedCodeCacheSize=480m 4. Now your IntelliJ IDE is implemented with more JVM memory for your every project, and you can run the game.
@JacobBohley
8 ай бұрын
Yeah I use Eclipse@@cristofferostberg1297
@Jushy_
Ай бұрын
Did you ever figure this out? I'm having the same problem
@JacobBohley
Ай бұрын
@@Jushy_ No I didn't cause I decided to do world size changes as well so map doesn't really work with that anyway.
YAY THANKS! If anyone has added new tilesets/maps I Was running into issue where I would get a : Cannot read field "image" because "this.tile[tileNum]" is null at tile.Map.createWorldMap(Map.java:40) at tile.Map.(Map.java:17) at main.GamePanel.(GamePanel.java:83) at main.Main.main(Main.java:17) Took me a second to figure out, but it was because I still had old maps that were not being used with old tilesets but I had not commented/deleted them out yet. Once I commented it worked just fine again.
@D.jerome387
Жыл бұрын
Hey, got the same issue and for me the problem was that there were no indexed tiles at 0,1,2,3,4,5,6,7,8,9 . I filled them in and it worked for me.
@mck1680
Жыл бұрын
Hello! Can you please tell me what you did? Because I have the same error code. I wanna full screen map work and Mini map too
I am getting white gaps between the tiles, how do I fix this @RyiSnow ?
Hello! Can somebody help me? When I am doing Map Screen and Minimap - How to Make a 2D Game in Java #47. I get errors: Exception in thread "main" java.lang.NullPointerException: Cannot read field "image" because "this.tile[tileNum]" is null at tile.Map.createWorldMap(Map.java:40) at tile.Map.(Map.java:19) at main.GamePanel.(GamePanel.java:61) at main.Main.main(Main.java:16). I have checked it and nothing is wrong. So please help me.
@teemukaik
Жыл бұрын
You probably don't have maps after 1 or 2?, You should set your maxMap to be same as your mapcount
@drefter4
10 ай бұрын
@@teemukaik ok but where shall I put it? please tell me?
@drefter4
10 ай бұрын
@@teemukaik The error I get when I try to get worldMap. They say Exception in thread "main" java.lang.NullPointerException: Cannot read field "image" because "this.tile[tileNum]" is null
@adnan2734
Ай бұрын
@@drefter4 in the GamePanel class, //World Settings, you will see public final int maxMap = something.I matched the map number i have so it fixed.You can press CTRL + left click while pointing maxMap to show its location.