Drawing Tiles - How to Make a 2D Game in Java #4

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

ความคิดเห็น • 395

  • @RyiSnow
    @RyiSnow  2 ปีที่แล้ว +39

    If you're not getting any errors but only seeing the grass tile,
    1. Take a close look at your file path (package name and file name) and make sure it is correctly referring to your map file. For example, if you type "/maps/map01.txt" while the actual package name is "map", the program cannot read the map file.
    2. Check your map file(.txt) and make sure space is inserted between numbers.
    String numbers[] = line.split(" ");
    This "line.split(" ")" means the program splits the line where space is inserted so you can split them and put them individually into the array. If no space is inserted in the map file, the program cannot render your map correctly.
    Basically, you can use any symbol for splitting lines. Space is just one way to handle it.
    Another example:
    String numbers[] = line.split("&");
    (Then insert & between numbers in the map file)
    This works too.
    3. Make sure to save the map file without BOM (Byte order mark). If the file contains BOM, the program fails to read the content correctly. Also, if your OS language is not English, saving it as UTF-8 might be safer.

    • @emilbogaci3715
      @emilbogaci3715 ปีที่แล้ว +2

      I have an error when I put loadMap
      The compiler throw numberformatexception: input string
      You the decimal format for the map

    • @doraymon7067
      @doraymon7067 ปีที่แล้ว +3

      I have error in tileManager line 30 the code is correct but hes still said input==null!?? What should be do?

    • @avery0719
      @avery0719 ปีที่แล้ว +1

      Thanks, somehow I keep getting the same problem. Perhaps I didn't check the BOM thing properly ? Idk, does someone have another solution

    • @barsaktas2012
      @barsaktas2012 ปีที่แล้ว

      For intellij Users
      public void loadMap(String filePath) {
      try {
      BufferedReader bufferedReader= null;
      filePath = "res/maps/map01.txt";
      bufferedReader= new BufferedReader(new FileReader(filePath));
      int col = 0;
      int row = 0;
      while (col < gp.maxScreenCol && row < gp.maxScreenRow) {
      String line = bufferedReader.readLine();
      while (col < gp.maxScreenCol) {
      String numbers[] = line.split(" ");
      int num = Integer.parseInt(numbers[col]);
      mapTileNum[col][row] = num;
      col++;
      }
      if (col == gp.maxScreenCol) {
      col = 0;
      row++;
      }
      }
      bufferedReader.close();
      } catch (IOException e) {
      e.printStackTrace();
      }
      }

    • @barsaktas2012
      @barsaktas2012 ปีที่แล้ว

      @@abikyoukan2 you should call it from TileManager method

  • @Nani-bk5op
    @Nani-bk5op 3 ปีที่แล้ว +197

    RyiSnow, you're a legend. Hardly anyone makes java game tutorials anymore, but you go above and beyond. Thanks bro 👍

    • @moonlightmacky9055
      @moonlightmacky9055 3 ปีที่แล้ว +15

      Ikr he's hella underrated. He really needs more views

    • @Nani-bk5op
      @Nani-bk5op 3 ปีที่แล้ว +8

      @@moonlightmacky9055 I swear. He's the greatest teacher ever!

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +37

      @Moonlight Macky @David Adames You guys are good at giving me motivation :P Thank you for the comment!
      And yeah Java might not be the most popular language for creating games but it's still powerful enough and has a lot of potential. I hope I can show the glimpse of it in this series.

    • @Nani-bk5op
      @Nani-bk5op 3 ปีที่แล้ว +6

      @@RyiSnow A lot of people choose other languages, but I still think Java is worth it. You have definitely shown me what Java can do. Thank you!

    • @ibrahimsultan7897
      @ibrahimsultan7897 2 ปีที่แล้ว +1

      @@Nani-bk5op it is

  • @jarrodmcevoy
    @jarrodmcevoy 3 ปีที่แล้ว +47

    You deserve thousands of more views. You're the only reason I'm continuing to learn programming after giving up on it for a year!!!

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +5

      Glad you're back!

  • @BrunoHenrique-oe5hb
    @BrunoHenrique-oe5hb 11 หลายเดือนก่อน +5

    You're no mediocre programmer. I've learned a lot with you, and i'm amazed by how you can explain things in a direct simple way. Thank you very very much. Greetings from Brazil, my teacher

  • @noemichulo8702
    @noemichulo8702 2 ปีที่แล้ว +18

    I have no idea how these videos don't get more attention, amazing tutorial. You explain everything well while not feeling slow. I usually watch these kinds of videos on 1.5x speed anyway and can't stay focused... You've kept my attention and taught me a lot!

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +4

      Happy to hear that!

  • @usEr-eX4OiDbU2S
    @usEr-eX4OiDbU2S 2 ปีที่แล้ว +14

    this is really educating!!!!
    BTW if someone is trying this -in the player class where you implement the public void update() method if you use while instead of if's you will get diagonal directions too because while pressing
    2 keys its gonna be true!

    • @alvins5054
      @alvins5054 2 ปีที่แล้ว

      I tried this but probably did something wrong as it didn't work, if you still have the code would it be possible for you to post it here? Diagonal movement would be really nice to have =)
      Thanks in advance!

    • @usEr-eX4OiDbU2S
      @usEr-eX4OiDbU2S 2 ปีที่แล้ว

      @@alvins5054 i was kinda wrong about that but i forgot to delete my comment...while in update() wont make you walk in diagonal movement, it just allows you to use more than one movement button at a time....but its easy to implement it from here on....with some extra methods checking while you are pressing for e.x W & D then move the player by that many X in horizontal and Z in vertical.

    • @alvins5054
      @alvins5054 2 ปีที่แล้ว +1

      @@usEr-eX4OiDbU2S Alright thanks for the answer. I managed to implement it in the if statement but thought there might be a better way of doing it. Anyways I'll post my solution as well just in case you're interested =)
      if (keyH.upPressed && keyH.rightPressed) {
      direction = "up";
      worldY -= speed;
      worldX += speed;

    • @usEr-eX4OiDbU2S
      @usEr-eX4OiDbU2S 2 ปีที่แล้ว +1

      @@alvins5054 thank you ! Ill try that in my while... It should work

    • @alvins5054
      @alvins5054 2 ปีที่แล้ว

      @@usEr-eX4OiDbU2S Let me know if you manage to make it a bit neater, now my if statement is pretty long. Also, I posted the code for collision detection during diagonal movement. The character got stuck otherwise so if you need it just check out video 6.

  • @joaovitorreynaldo
    @joaovitorreynaldo 2 ปีที่แล้ว +5

    After learning what I need, I can only come here and thank you for the java tutorials!

  • @tsupi7056
    @tsupi7056 2 ปีที่แล้ว +39

    For those who have null error, change this part:
    tile[0] = new Tile();
    tile[0].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/grass.png"));
    tile[1] = new Tile();
    tile[1].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/rock_path.png"));
    tile[2] = new Tile();
    tile[2].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/water.png"));
    to this:
    File file = new File("src/res/floor/grass.png");
    FileInputStream fis = new FileInputStream(file);
    tile[0] = new Tile();
    tile[0].image = ImageIO.read(fis);
    file = new File("src/res/floor/rock_path.png");
    fis = new FileInputStream(file);
    tile[1] = new Tile();
    tile[1].image = ImageIO.read(fis);
    file = new File("src/res/floor/water.png");
    fis = new FileInputStream(file);
    tile[2] = new Tile();
    tile[2].image = ImageIO.read(fis);
    it worked for me

    • @veteran_gaming2698
      @veteran_gaming2698 2 ปีที่แล้ว +1

      Thank you for this alternative code. It worked just fine for me!

    • @newuser689
      @newuser689 2 ปีที่แล้ว +2

      original probably didn't work because you put "src/res" in the stream string

    • @pradhu6939
      @pradhu6939 ปีที่แล้ว +1

      The original code worked for me when I added 1 to each of the indexes.
      The code would like:
      tile[1 (not 0)] = new Tile();
      tile[1].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/grass.png"));
      tile[2 (not 1)] = new Tile();
      tile[2].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/rock_path.png"))
      tile[3 (not 2)] = new Tile();
      tile[3].image = ImageIO.read(getClass().getResourceAsStream("src/res/floor/water.png"));

    • @yojimboflamel
      @yojimboflamel ปีที่แล้ว +1

      Thank you! the only difference for me was the path to the file I had assigned differently as "res/tiles/water.png"
      It worked perfectly :)
      Also I imported
      import java.io.File;
      import java.io.FileInputStream;

    • @Arian11111
      @Arian11111 ปีที่แล้ว

      @@yojimboflamel for me it worked to just call the method "getTileImage();" before u draw it.

  • @arrislongington9242
    @arrislongington9242 2 ปีที่แล้ว +4

    RyiSnow, this tutorial series is phenomenal, really straightforward and clear to the point where I'm able to make a functional game with just this video. Thank you so much and please continue this series.

  • @klanehz6291
    @klanehz6291 3 ปีที่แล้ว +1

    I quit java programming 1 year ago but now thanks to your tutorial i can start learning again, THANKS!!

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      That's great to hear! Please come along with us!

  • @gerardogrossi8775
    @gerardogrossi8775 11 หลายเดือนก่อน +1

    RyiSnow you`re an inspiration really ! You gave everyone who loves RPG games a big present, with no doubts the most complete tutorial on TH-cam.
    Thank you very much ! with love from Italy to Japan !

    • @RyiSnow
      @RyiSnow  11 หลายเดือนก่อน +2

      Grazie for the warm message!

  • @VasiliyNikitin
    @VasiliyNikitin ปีที่แล้ว

    The result in the form of displayed tiles and a character causes pleasure and a smile. Thanks!

  • @nickolasthompson431
    @nickolasthompson431 2 ปีที่แล้ว +10

    I'm not sure if you're still answering questions on here, but I'm running into a problem where my map is only loading my grass png. While watching your video, I saw where you forgot to add loadMap(); but I am still running into this problem after adding that in.

    • @DougHigashi
      @DougHigashi 2 ปีที่แล้ว

      Are you loading the correct files in ImageIO.read()?
      As in ImageIO.read(getClass().getResourceAsStream("/tiles/grass.png"));
      ImageIO.read(getClass().getResourceAsStream("/tiles/water.png"));
      ImageIO.read(getClass().getResourceAsStream("/tiles/wall.png"));

    • @postulysses
      @postulysses 2 ปีที่แล้ว +1

      Hello ,I encountered the same problem. It fills with grass.png because the getClass().getResourceAsStream("/maps/map01.txt") probably returns null .I suggest the following solution: I passed the file path and name to a public final static String . Then the getClass(). getResourceAsStream () worked without problems.
      The code :
      ....
      public class TileManager {
      GamePanel gp;
      Tile[] tile;
      public static final String fileName = ( "/maps/map01.txt");
      .....
      And at
      InputStream is = getClass(). getResourceAsStream (fileName);

    • @jazfromyt
      @jazfromyt ปีที่แล้ว +1

      @@postulysses did not work

    • @bread3453
      @bread3453 ปีที่แล้ว

      @@postulysses I'm still getting the null error. I know the map directory is correct bc it shows me the file details when I go over it and I've even tried your method here. Still getting a null error for "is".

  • @kandiman9111
    @kandiman9111 3 ปีที่แล้ว +8

    I love these tutorials, I can't wait to get started on trying this! You deserve so much views, thanks so much! :)

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      You're welcome. Thank you for the comment!

  • @fssimply
    @fssimply 2 ปีที่แล้ว +6

    For those using his tiles, the ones with the numbers... here is an automatic way of adding all of them:
    for (int i = 0; i < 38; i++) {
    tile[i] = new Tile();
    tile[i].image = ImageIO.read(getClass().getResourceAsStream("/tiles/0" + (i < 10 ? "0" + i : i) + ".png"));
    }
    the tiles as of right now are 37 but add 1 more to add them all. Also if you add more yourself the rember to change (i < 10 ? "0" + i : i) this. I made it like that for 99 tiles or less.

  • @EntificationALTWow
    @EntificationALTWow 2 ปีที่แล้ว +5

    22:20 you don't need to put the "if" statement because after the while loop there is a 100% chance of col being 16 (or maxScreenCol if you put something else).

  • @jordi5316
    @jordi5316 2 ปีที่แล้ว +1

    Even tho i have i no clue what is going on 90% of the time. I still enjoy it very much. Thank you

  • @gianad2314
    @gianad2314 2 ปีที่แล้ว +11

    If you have problems with the map displaying only grass ( or whatever png you have saved in tile[0].image) It could be that the loadMap() function can't read the map01.txt file. The result is that the mapTileNum matrix is filled with 0 which is the default value.
    You can try other file reading methods, here is the one I used :
    private void loadMap(String filepath) throws FileNotFoundException {
    Scanner scanner = new Scanner(new File(filepath));
    int row = 0;
    int col = 0;
    while(scanner.hasNextInt())
    {
    System.out.println(col);
    mapTileNum[row][col++] = scanner.nextInt();
    if(col > gp.maxScreenCol-1){
    row++;
    col = 0;
    }
    }
    }
    If you use a map that is bigger than the number of tiles on the screen, you have to replace the if condition like so :
    if(col > numberOfColInYourMap - 1)
    Once again I hope this can help someone and thanks for the amazing tutorials!

    • @postulysses
      @postulysses 2 ปีที่แล้ว

      Thank you very much for the solution ! I followed your method after trying many times with getClass().getResourceAsStream() and receiving nullPointerException. However I insisted in using getResourceAsStream and find another solution. I passed the file path and name to a public final static String . Then the getClass(). getResourceAsStream () worked without problems.
      The code :
      ....
      public class TileManager {
      GamePanel gp;
      Tile[] tile;
      public static final String fileName = ( "/maps/map01.txt");
      .....
      And at
      InputStream is = getClass(). getResourceAsStream (fileName);
      Thank you very much again !

    • @frida8856
      @frida8856 ปีที่แล้ว +1

      Hi, I need help, im trying the method you used instead of the one in the video but it gives me an error
      Unhandled exception: java.io.FileNotFoundException

    • @gybo_winner
      @gybo_winner ปีที่แล้ว

      @@frida8856 same for me

    • @gybo_winner
      @gybo_winner ปีที่แล้ว

      not working correctly for me

    • @jamiebarr3118
      @jamiebarr3118 ปีที่แล้ว

      @@postulysses
      Hey everyone, I fixed my grass issue somehow after adding a space at the end of each row in the text file (I think it might help bc when you parse it checks for spaces?). Also, after adding in the txt file to /res, open it in intelliJ or wherever to make sure it's just 0's 1's and 2's

  • @Alpheus_09C
    @Alpheus_09C 6 วันที่ผ่านมา

    you are amazing dude, im finally working on my dream to create games, all thanks to you man

  • @sorcerian_bootleg7112
    @sorcerian_bootleg7112 3 ปีที่แล้ว +5

    Keep it up! Looking forward for the next entry in the series!
    Also, it could be cool to make a tutorial on how to make those tile managers, like the ones you showed in one of the previous series to make everything more visual and easier when creating bigger maps.
    In other hand, there's something that caught my attention on the character movemet, or rather, when the character stops walking. I see that when it stops walking it shows the lastest sprite it was displaying at that moment, instead of going back to the first sprite. A stand still position, so to speak. How could you make it so when the character stops walking it displays a specific sprite of the animation?

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +7

      Glad you liked this series! About the player sprite, the easiest fix would be adding this line following the "key pressed" if statement in Player class:
      else {
      spriteNum = 1;
      }
      Then when you are not pressing any keys, the sprite is set as 1. If you want to make it look more natural maybe you want to create another counter and count the interval for this one as well like this:
      else {
      counter2++;
      if(counter2 == 20) {
      spriteNum = 1;
      counter2 = 0;
      }
      }
      Then it takes 20 frames until player returns to stand still position.
      About the tile editor, I thought about implementing it in this tutorial at first but gave up the idea. It would likely take 10+ videos for the editor itself (it's actually a pretty huge program) and that will be too much sidetracking (and require a lot of extra energy!) If I make the editor tutorial, it will be at least after finishing this series. Sorry about that!

  • @jonbonjesus1224
    @jonbonjesus1224 2 หลายเดือนก่อน

    haha i was thinking "Surely he's not going to hard code each tile onto each piece of the screen!" You got me worried lol Thanks for the videos! I'm making my own game but these tutorials are helping me so much

  • @moonlightmacky9055
    @moonlightmacky9055 3 ปีที่แล้ว +5

    Man you're amazing, I wish you'd get more subs, keep it up brother!

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +2

      Thank you! Now preparing the part 5 and I can say it will be a pretty interesting episode so please stay tuned!

  • @pianintendo
    @pianintendo 2 ปีที่แล้ว +1

    Hey ! Very very nice tutorial serie, I really enjoy it. Just a little optimization comment : I think it's better to put the String numbers[] = line.split(" "); outside the second while loop, but in the first one, this will avoid numbers[] filling repetition as it changes only when we change row !
    (I'm actually proud to be able to see it, this mean I understand very well what I'm doing and you're totally a part of it so thank you again for this amazing tutorial)

    • @avery0719
      @avery0719 ปีที่แล้ว

      Hi, I am having a bug where the first tile just keeps repeating over and over again. I think to solve it I should move the numbers[] = line.split(" "); to another line. However, I didn't find to which line should I move it. Could you explain to me where do you move it? (sorry for my grammar, I am french)

  • @LouShunt
    @LouShunt 3 ปีที่แล้ว +4

    I love this series! Keep up the good work.

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      Happy to know that you are enjoying this!

  • @yahya220111
    @yahya220111 2 ปีที่แล้ว +2

    Hello sir
    Thanks for the awesome series
    I just have one question
    When i'm using the draw method to draw the map it doesn't work , it just gave me a white bored and like it's lagging
    I tried to use netbeans but it also have the same problem
    When i don't use the draw method it works,running the game with the black background i mean
    Can you tell me what is the problem?

    • @medgouyahia398
      @medgouyahia398 2 ปีที่แล้ว

      make sure u called getTileImage() in the constructor of TileManager

  • @m4yflyjr855
    @m4yflyjr855 ปีที่แล้ว +2

    Im having a problem with tileNum inside this line: g2.drawImage(tile[tileNum].image, x, y, gp.tileSize, gp.tileSize, null); it doesnt run but when i replace the tileNum with 1 it prints the according tile to the whole screen and runs fine, so i know it must be a problem with the tileNum no? any help is appreciated

  • @hanno-oz3ip
    @hanno-oz3ip 2 ปีที่แล้ว +1

    best tutorial series ive ever seen. and ive seen lot! Thank you so much

  • @TuyetNguyen-lj6mh
    @TuyetNguyen-lj6mh 10 หลายเดือนก่อน

    You are the best!!! Just wanted to say thank you for all the details, it helps a lot for Java beginner.

  • @yajie7756
    @yajie7756 2 ปีที่แล้ว

    i really like your pixel art! it's very cute! i just like watching the player walking around~ I think i'll go through the entire serie because your little blue boy makes me feel happy :))) hope i can draw something so sweet too! Good day~

  • @tranminhquang7368
    @tranminhquang7368 3 ปีที่แล้ว +2

    Perfect. Hope you make more videos like this.
    Wish your channel grow.

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      More videos are in the make! Thank you for the comment.

  • @edward265
    @edward265 3 ปีที่แล้ว +2

    I love java. I have never tried this but I might now.

  • @ecernosoft3096
    @ecernosoft3096 ปีที่แล้ว

    Whoever you are,
    *You’re a legend.*

  • @lucasa6597
    @lucasa6597 ปีที่แล้ว +7

    for those are using VS code , if the map is not working use this line:
    InputStream is = new FileInputStream("../../maps/map01.txt");

  • @ntramu4186
    @ntramu4186 11 หลายเดือนก่อน

    You are my savior sir, thanks a lot

  • @sphericalfutures4185
    @sphericalfutures4185 ปีที่แล้ว +2

    RyiSnow, I just want to say that you're awesome. And I really mean it, you're the only one on TH-cam to make a Java tutorial like this, so comprehensible, so... awesome! I'm using a lot of your code here to complete my high school project. I also like how you're Japanese; I'm learning the language right now and I'm almost fluent. God bless you and keep well man.

  • @tarnum113
    @tarnum113 2 ปีที่แล้ว +1

    Thanks from Russia! Such a great content! Always had a dream to make a game in Java!

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +2

      Hi! Glad you enjoyed it. Good luck on your development :)

  • @basslinessoulhouse9435
    @basslinessoulhouse9435 หลายเดือนก่อน +1

    You didn't include the getImage method but the program was still running. When i did that it gave me an error so i added it above the tileM.getImage method above the tileM.draw method and it started working

  • @CeorlCode
    @CeorlCode 7 หลายเดือนก่อน

    Yo bro, I just want to let you know that you're LEGEND!!!!!!!!
    btw I'll comment every single video so I can see the day or progress I made as a beginner.

  • @EntificationALTWow
    @EntificationALTWow 2 ปีที่แล้ว

    I made a few useful like getting the coordinates needed to place something in the middle of the screen (like the player) and one for seeing how many pixels are needed to place a tile in a certain position (like if I want it to be on the 5th tile from the left I could call the function and input 5 and it would return the exact number of pixels needed)

  • @OM-yn8pt
    @OM-yn8pt 3 ปีที่แล้ว +4

    I remember during your zelda tutorial you took my suggestion of making a function to allow your to click an drag to draw tiles on the map editor you made, funny to see you make another tutorial where you are doing a similar project, this video reminded me of that a few months ago! Great tutorial as always, i recently did something similar in python with pygame

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +2

      Yup I remember that too. I knew this was going to be a long series and require a lot of effort to make so I was putting it on ice for like a year but now I'm glad I could finally start it!

  • @udaybhokre591
    @udaybhokre591 2 ปีที่แล้ว +3

    There is one problem
    When I call the draw of TileManager method in paintComponents method of Gamepanel,
    the whole game becomes plain white please help

    • @gybo_winner
      @gybo_winner ปีที่แล้ว

      Same problem for me

    • @brendacchebet
      @brendacchebet ปีที่แล้ว

      me too, did u ever solve it?

  • @kamisama1712
    @kamisama1712 2 หลายเดือนก่อน

    Thanks Ryi snow! doing this tutorial for the second time!

    • @RyiSnow
      @RyiSnow  2 หลายเดือนก่อน

      Welcome back!

    • @kamisama1712
      @kamisama1712 2 หลายเดือนก่อน

      @@RyiSnow now that I understand more about programming I’m excited to redo this. Thanks so much for helping me find my path

  • @hizokadarkwolf
    @hizokadarkwolf ปีที่แล้ว

    this one was hard. I changed the loading of tiles by using a FOR that saves each new texture to an array of tiles. Also, all the public attributes I have changed them to private or final, but with getters it can be read from anywhere else in the app.
    Good tutorial, now I need to sleep it's 4.12 AM here.

  • @bossman6167
    @bossman6167 11 หลายเดือนก่อน

    Love the guides its helping me a lot. Quick question: If i where to code this game could i do so in visual studio code? Thanks ❤

  • @vyom5663
    @vyom5663 9 หลายเดือนก่อน +1

    After creating Shortcut of making map ( txt file method ) , my player is lagging and map is not created properly . only upper wall is been made and rest all are grass . plz help
    but by using the 9:00 method it's working.
    I use intellij . Plz give a solution for this

    • @coldbacon冷気
      @coldbacon冷気 8 หลายเดือนก่อน +1

      hey man i had the same issue, try double-checking that in you draw method you increment y by gp.tileSize -> if(col == gp.maxScreenColumns){
      col = 0;
      x = 0;
      row++;
      y+= gp.tileSize; //What i forgot
      }

  • @maximhanzely1988
    @maximhanzely1988 2 ปีที่แล้ว +2

    Hi i have a problem when i try louding out of txt. our classes for the map are looking same (cant see difference, compared with video like 3 times) but I am getting this error: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Sounds like you're trying to read something which is out of the array bounds.

    • @lostparlour
      @lostparlour ปีที่แล้ว

      did you fix it? i got it too.. thanks

  • @NikitaBomba112
    @NikitaBomba112 2 ปีที่แล้ว +1

    Thanks you very much for this video!

  • @JakeAAustin
    @JakeAAustin 2 ปีที่แล้ว

    Thanks RyiSnow. Really enjoying this series!

  • @datdang1478
    @datdang1478 2 ปีที่แล้ว

    Love you RyiSnow! You are our Legend. I appreciate what you've done for us!

  • @ЮрийНиколаевич-д2б
    @ЮрийНиколаевич-д2б 2 ปีที่แล้ว

    Thank you very much, RyiSnow! Your tutorials are wonderful.

  • @drspinfire1680
    @drspinfire1680 ปีที่แล้ว +2

    Hey RyiSnow,
    Whenever I run the program the render is all white and none of the tiles or the player is shown. Do you know what may have happened?
    Edit- Nevermind, got it to work

    • @shreyankagitala4285
      @shreyankagitala4285 ปีที่แล้ว

      Could I ask how you fixed that? I am having the same problem.

    • @QuanTran-pc3cx
      @QuanTran-pc3cx หลายเดือนก่อน

      @@shreyankagitala4285 I'm having the same issue

  • @joumakesgames
    @joumakesgames 2 ปีที่แล้ว +1

    Hi RyiSnow, your tutorials are very good and I've been following them and learning a lot from them. One question though, when loading the map, it only loaded the row[0] for me over and over, it wont go to row[1] and so on. I read my code and checked yours and there wasnt any problem that i can see. what could be the fix for this?

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +1

      May I see your code?

    • @anao3683
      @anao3683 2 ปีที่แล้ว +3

      Hey, I've had a similar issue, turns out that in the TileManager class, loadmap() method, I put br.close() inside the while loop on accident, when it should be outside, so that it printed only the [0] tiles after the first row. Maybe that is the issue?

    • @joumakesgames
      @joumakesgames 2 ปีที่แล้ว +1

      btw i fixed this issue, instead of doing nested while, i just used nested ifs in the x and y axis and it loaded fine

    • @kishank593
      @kishank593 2 ปีที่แล้ว +1

      @@anao3683 Thanks, I had the same issue and this fixed it.

    • @ibrahimsultan7897
      @ibrahimsultan7897 2 ปีที่แล้ว +1

      @@joumakesgames hey can you show me that code?

  • @PotatoChips1223
    @PotatoChips1223 2 ปีที่แล้ว

    this is the most epic game made in java good work!

  • @chochi7962
    @chochi7962 4 วันที่ผ่านมา

    I have a problem but not with the code. I cant make my image with transparent background. Can someone help me.

  • @roddito
    @roddito ปีที่แล้ว +1

    My map only works, if I remove the space on the line.split("") method, with space it throws a exception, but i am loving learning this.

  • @meatlover6916
    @meatlover6916 3 หลายเดือนก่อน

    I got a java.lang.NullPointerException error when I tried dereferencing the InputBuffer object in TileManager...

  • @Locras
    @Locras 3 ปีที่แล้ว +3

    This is amazing! Thank you

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      Glad to hear that! Thank you for the comment.

  • @SlothfulSage285
    @SlothfulSage285 2 ปีที่แล้ว

    Another great video! I am glad I found this series!

  • @travisv4189
    @travisv4189 ปีที่แล้ว +1

    I’m running into the problem where only the first 16 col tiles are loading based on what my txt files shows. Everything else comes up as grass. Any advice?

    • @kwabaj1585
      @kwabaj1585 ปีที่แล้ว

      I'm having this issue too. Not sure why.

    • @abikyoukan2
      @abikyoukan2 ปีที่แล้ว

      same. tried changing the code to one in the comments but nothing. very strange. it seems as if its only reading the first line of the text file

  • @HANLYU-jx9jl
    @HANLYU-jx9jl ปีที่แล้ว

    This is a wonderful series! I wonder how you learned game programming.

  • @TheClockmister
    @TheClockmister ปีที่แล้ว

    Why do you not encapsulate fully? Some fields seem only to be accessed by the class itself

  • @luciuscouto4592
    @luciuscouto4592 2 ปีที่แล้ว +1

    How can I draw tiles where the player passes behind?

  • @DravenFNM
    @DravenFNM 3 ปีที่แล้ว +1

    Enjoying the series a lot :)

  • @meltedice2186
    @meltedice2186 2 ปีที่แล้ว +1

    Hey RyiSnow! Thank you for this tutorial!
    I am facing a problem where my entire map isn't loading. Only half of it is being displayed. Please may you help? Thank you!

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Are you getting any error message?

    • @meltedice2186
      @meltedice2186 2 ปีที่แล้ว

      @@RyiSnow No, i am not getting any error message but the tiles in the bottom of the screen aren't being displayed.
      Please may you help me with that

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Can I see your TileManager class? You can paste it here (probably with a little comment to prevent it regarded as a spam)

    • @meltedice2186
      @meltedice2186 2 ปีที่แล้ว

      @@RyiSnow Hey! Thank you, i watched your 5th part- World and camera and now it works properly. Thanks!

  • @Locras
    @Locras 3 ปีที่แล้ว +3

    Can you put the tiles in your google drive?

    • @RyiSnow
      @RyiSnow  3 ปีที่แล้ว +1

      Sure, I just put the link in the description!

  • @shanec9869
    @shanec9869 ปีที่แล้ว +2

    UPDATE:
    I had put br.close(); into the wrong spot.
    I've run into an issue where my map is only reading the first line - the rest of the map is displaying only grass regardless of the numbers I list. Anyone know where I might have went wrong/what to do? I've rewatched the video but can't find my mistake in code.

  • @DaniloMotaSoares
    @DaniloMotaSoares 2 ปีที่แล้ว

    Can I use and Excel file for the map? I think managing tile positions, rows and columns should be easier.

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Sure if that's easier for you. That said this tutorial is based on text file maps so if you follow this series, you'll need to do some adjustments by yourself from time to time.

    • @DaniloMotaSoares
      @DaniloMotaSoares 2 ปีที่แล้ว

      @@RyiSnow Sure, sure, sensei. I'm aware. I'm following your guide, but making my own adjustments, like using a intermediate "idle" sprite in the walking animations to help make the switch between them more fluid, as well as I'm using 64px tiles instead of a 16 px scaled 3 times up.
      That said, the tutorial is very good and you explaining WHY are doing the things you do instead of just doing it is the quality standard here. Thanks for the effort!

  • @sujeetyadav7193
    @sujeetyadav7193 ปีที่แล้ว +1

    i am getting a java.lang.NullPointerException: Cannot read field "image" because "this.tile[0]" is null error with a while blank screen what to do?

    • @LYNDONCABUG
      @LYNDONCABUG หลายเดือนก่อน

      HEYY have you finished the problem? Im on the same error! pls help :(

  • @roddito
    @roddito ปีที่แล้ว +1

    Can we make a for loop inside a for loop, instead of while in the draw method of TileManager? Yes?

    • @RyiSnow
      @RyiSnow  ปีที่แล้ว

      Yes, we can :)

  • @adityagaur8163
    @adityagaur8163 ปีที่แล้ว +1

    Ryi show I have a question
    Can we create a map without loop and it's working? //Like using path and set in pixels location
    Because my pc is low pls replay me I want to create game and learn 😔

  • @laz3664
    @laz3664 ปีที่แล้ว

    Thanks so much for making these!! You're a legend

  • @XQZFirefly
    @XQZFirefly ปีที่แล้ว +1

    Got a bug in the TileManager Class with the File Input of the Map: The inStream was null.
    Using is = FileInputStream("mapname.txt) instead of InputStream.getClass().getResourceAsStream("...") fixed it for me.
    Anyway thank you for your tutorials :)

  • @nicktorius8910
    @nicktorius8910 6 วันที่ผ่านมา

    My map is only loading my grass png even after add loadMap(); I am still running into this problem after adding that in

  • @davyswanson7412
    @davyswanson7412 2 ปีที่แล้ว

    amazing videos and a great teacher,thanks for all the help

  • @Hyperblaze456
    @Hyperblaze456 2 ปีที่แล้ว

    This video is great!
    Am trying to make games and this rly helped, but is there any way to increase the player width or height?

  • @justguni7324
    @justguni7324 11 หลายเดือนก่อน

    Hello, for some reason my loaded Tiles look "slashed" in the diagonal. They are slightly shifted in themselfes in the diagonal. I don`t know how to fix that, can you please help me?

  • @templeOfChrist1994
    @templeOfChrist1994 ปีที่แล้ว

    Not sure why but, my map is only reading the very first number in the map.txt file "i have tested" by changing the first number and it changes the entire look of map to grass; or wall; or water whatever which i choose.

  • @beautifulmama7851
    @beautifulmama7851 2 ปีที่แล้ว

    what could cause it to only display the top 16 row with the other tiles but the rest of the bottom is just the grass? i have tryed changing the numbers on the bottom to see if they would display and nothing =/

  • @andrasfejes8988
    @andrasfejes8988 2 ปีที่แล้ว

    the file structure is EXACTLY the same in my program. Yet I get a nullpointer error. Why?

  • @helgertluca
    @helgertluca 3 หลายเดือนก่อน

    ありがとうございます!

  • @Sheczybaddoh
    @Sheczybaddoh ปีที่แล้ว

    I try to run if after doing the tile loop for but when I run the game I am just seeing a white screen

  • @legocat9361
    @legocat9361 2 ปีที่แล้ว +2

    Great tutorial! I just finished your text based adventure game series and decided to try this one! But I ran into a problem, my code just displays a panel full of grass tiles. I checked my code with yours but I cant find where I went wrong. How could I fix this?
    Heres the code:
    package tile;
    import java.awt.Graphics2D;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import javax.imageio.ImageIO;
    import main.GamePanel;
    public class TileManager
    {
    GamePanel gp;
    Tile[] tile;
    int mapTileNum[][];

    public TileManager(GamePanel gp)
    {
    this.gp = gp;
    tile = new Tile[10];
    mapTileNum = new int[gp.maxScreenCol][gp.maxScreenRow];

    getTileImage();
    loadMap("/maps/map_text.txt");
    }

    public void getTileImage()
    {
    try
    {
    tile[0] = new Tile();
    tile[0].image = ImageIO.read(getClass().getResourceAsStream("/tiles/tile_grass.png"));

    tile[1] = new Tile();
    tile[1].image = ImageIO.read(getClass().getResourceAsStream("/tiles/tile_water.png"));

    tile[2] = new Tile();
    tile[2].image = ImageIO.read(getClass().getResourceAsStream("/tiles/tile_floor.png"));

    tile[3] = new Tile();
    tile[3].image = ImageIO.read(getClass().getResourceAsStream("/tiles/tile_wall.png"));

    }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 < gp.maxScreenCol && row < gp.maxScreenRow)
    {
    String line = br.readLine();

    while(col < gp.maxScreenCol)
    {
    String numbers[] = line.split(" "); //splits up strings at space
    int num = Integer.parseInt(numbers[col]);
    mapTileNum[col][row] = num;
    col++;
    }

    if(col == gp.maxScreenCol)
    {
    col = 0;
    row++;
    }
    }
    br.close();

    }catch(Exception e){
    }

    }
    public void draw(Graphics2D g2)
    {
    int col = 0;
    int row = 0;
    int x = 0;
    int y = 0;

    while(col < gp.maxScreenCol && row < gp.maxScreenRow)
    {
    int tileNum = mapTileNum[col][row];
    g2.drawImage(tile[tileNum].image, x, y, gp.tileSize, gp.tileSize, null);
    col++;
    x+= gp.tileSize;

    if(col == gp.maxScreenCol)
    {
    col = 0;
    x = 0;
    row++;
    y += gp.tileSize;
    }

    }
    }
    }

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว +1

      Can I see your TileManager class? You can paste it here.

    • @legocat9361
      @legocat9361 2 ปีที่แล้ว +1

      @@RyiSnow I edited my comment and pasted it in!

    • @RyiSnow
      @RyiSnow  2 ปีที่แล้ว

      Thanks. I changed the tile names to mine then the tiles were displayed correctly. So I think something is wrong with your file name or path. Check if those names/paths are indeed identical to your image file names and paths.
      By the way, are you getting any error message?

    • @aalimomin4637
      @aalimomin4637 2 ปีที่แล้ว

      @@RyiSnow thanks I had the same problem

    • @ksportalcraft
      @ksportalcraft ปีที่แล้ว

      Thanks!

  • @brunobatista5258
    @brunobatista5258 2 ปีที่แล้ว

    very talented teacher - cheers

  • @nickmelillo5795
    @nickmelillo5795 ปีที่แล้ว

    im trying to export this in order to send to friends, and the jar file just does not open, i was able to send a previous version earlier though

  • @Daniel-lc7cw
    @Daniel-lc7cw ปีที่แล้ว

    Nice video! more explaination would be better . whats a Buffer/BufferedImage/InputStream/line.split but it was still easy to understand!!

  • @wizco4443
    @wizco4443 2 ปีที่แล้ว +1

    Can someone help fix my error
    "The type of expression must be an array type but it resolved to int"
    It happens on both
    Int tileNum = mapTileNum[col][row];

    • @wizco4443
      @wizco4443 2 ปีที่แล้ว

      Nvm I got it, make sure to save...

  • @erpresident1312
    @erpresident1312 ปีที่แล้ว

    Would Scanner work the same as InputStrem and BufferedReader?

    • @RyiSnow
      @RyiSnow  ปีที่แล้ว

      Coding is not the same but I think Scanner works too.

  • @cedricsahaghian1605
    @cedricsahaghian1605 ปีที่แล้ว

    Thank you so much!

  • @saintlaron3862
    @saintlaron3862 ปีที่แล้ว

    Load map wasn’t working for me I had to draw them manually 😅 when it read my text file it was only getting back 1s and 2s but I had 3s and 4s also

  • @ducganktem201
    @ducganktem201 ปีที่แล้ว

    8:46 i'm kinda confused on the x-coordinate, how did you calculate the x-coordinate for the second tile to get x = 48 ?

    • @WhiteKran
      @WhiteKran 11 หลายเดือนก่อน +1

      Their tiles are 16x16, and their scale is set to 3 so each tile is scaled up by 3. Now each tile takes up 48 pixels, so they need to be 48 pixels apart from each other to avoid overlapping.
      To do this yourself, even if your scale or originalTileSize is different you just have to multiply your originalTileSize by your scale then displace each tile by the new tile size.

    • @ducganktem201
      @ducganktem201 11 หลายเดือนก่อน

      @@WhiteKran shid, thanks brother that makes more sense. it took me a long time trynna understand the scale thingy

    • @WhiteKran
      @WhiteKran 11 หลายเดือนก่อน

      @@ducganktem201 Glad to be of help bro

  • @boredom730
    @boredom730 11 หลายเดือนก่อน

    whats the size in pixels of the tile images?

  • @bigbear8485
    @bigbear8485 ปีที่แล้ว

    it was a bit relieving when I paused the tutorial to continue a little on my own, question why the map isn't loading the data, go through each line of code one by one only to realize I didn't load the map, then unpausing the video and seeing that the same had happened to you

  • @hggnomm
    @hggnomm ปีที่แล้ว

    Incredible !! I admire you

  • @roccionegrande
    @roccionegrande ปีที่แล้ว

    Mine lagging, idk why. Maybe because I use NetBeans for programming? (My pc has good components so it's not that)

  • @mamapuci
    @mamapuci 2 ปีที่แล้ว

    Hehey... Im here too. Thanks buddy.

  • @julianbertignoll5323
    @julianbertignoll5323 2 ปีที่แล้ว

    Keep it up! Your videos are the best but for me only the first row of the txt file loads. the rest is grass. is it because i use netbeans

  • @vampybitesss
    @vampybitesss ปีที่แล้ว

    added tracer code to find the problem
    not sure how to fix, but when my try loop goes to read the second line of a file it fails. the file is the correct format and works first loop through. its the reading of the next line itself that causes the try to trip. trying to just eat the next line on its own also causes the try to trip
    would appreciate help!

    • @vampybitesss
      @vampybitesss ปีที่แล้ว

      i was closeing the reader inside the while loop instead of after

  • @kid3545
    @kid3545 2 ปีที่แล้ว

    THANKS FOR THIS IV BEEN SEARCHING FO SOOO LONG

  • @nikoman4785
    @nikoman4785 ปีที่แล้ว

    Ryi I get this huge error it happened in the end of the video and the errors are ususally happening in the other classes i didnt make THERES SO MUCH ERRORS

  • @amc1140
    @amc1140 2 ปีที่แล้ว +1

    great video but the ads are overkill