GRAVITY - Episode #10 - Platformer Tutorial Java

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

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

  • @KaarinGaming
    @KaarinGaming  2 года назад +9

    Hey guys! :D
    What would you like to see next in the tutorial?
    Leave a comment below.
    Cheers !

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

      Attacking enemies and collectibles would be great ! These tutorials are amazing by the way keep up !

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

      You have a bug in the game, when you hold the A and D keys down the character is showing the running animation.

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

      You are right.
      Something we will have to address in the next episode =)

  • @hadefahmed3338
    @hadefahmed3338 4 месяца назад +1

    It's my first try in game development. I'm good at programming, but I've been a bit scared about game development. You've made it easy for me to start. You deserve millions of subscribers. Thank you!

  • @gigibecali3868
    @gigibecali3868 2 года назад +5

    I'd love multiple levels or maybe a menu state!
    Thank you so much for everything, you help me a lot with my asignments!

  • @agrunek
    @agrunek 2 года назад +6

    Hello Kaarin! Firstly, I want to adress one issue that I saw some people including me had: changing the hitbox height to 27 * SCALE pixels started causing strange problem that made our little pirate go insane. Apparently "inAir" flag was lighting up although player character was walking on the ground. The problem doesn't show up if we use for the SCALE whole numbers, so I came to conclusion that the function isEntityOnFloor() checks float values that are always rounded down while casting to int in isSolid() function. So I came with kinda bad looking solution, that I have no idea if it won't mess something up:
    public static boolean isEntityFloating(Rectangle2D.Float hitbox, int[][] levelData) {
    float yOffset = hitbox.y + hitbox.height + 1;
    if(yOffset != (int) yOffset) {
    yOffset = (int) yOffset + 1;
    }
    return isTransparent(hitbox.x, yOffset, levelData) &&
    isTransparent(hitbox.x + hitbox.width, yOffset, levelData);
    }
    *Despite me using functions with opposite logic than yours those 4 first lines of rounding up Y values apparently helps for now...
    Okay, so... Secondly, I want to thank you for all the work and love you have put in this tutorial series!!! I am total noob at java and started learing it 2 weeks ago. After finishing java basics tutorial I found your video and I don't regret watching it. I learned a lot of new and useful things, that will not be only helpful in game dev but in java programming as a whole. I can't wait to watch the rest! If I ever hear one of my friends from university will start learning this beatiful language I will deffinetly recommend them this tutorial ;)
    I hope your channel will blow up, because you deserve it 💚

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

      Hey. Thanks for the comment.
      Regarding this issue you speak of, I think we solve it later, by making sure that the width and height cannot have any decimal.
      As of this video, the height is set by height * Scale.
      But later we say:
      (int)(height * Scale)
      By doing this, we can have scale 1.5 for example, but the height of the hitbox, does not contain any decimals.
      I do like it though when people address bugs on their own. And thank you for the kind words. I hope you learn more from the coming episodes of this tutorial. :D

  • @gepeto152
    @gepeto152 Год назад +8

    What can I do if my hitbox have a greater width and height than 1 tile?

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

    Changing the hitbox to 27 gave a bug where the hitbox got stuck at 1 pixel above the floor. This was because of the SCALE being 1.5f. I fixed it by casting 27*SCALE to an (int). Here's to hoping this doesn't break anything in the future.
    Also because of messing with SCALE made me notice that the player moved way faster in a smaller window because playerspeed wasn't multiplied by SCALE.

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

      You sir, are 100% right. It also felt off to me how the speed increases when decreasing the scale ^^

  • @pennythoughts
    @pennythoughts 2 года назад +9

    What do you do if your sprite has a smaller width than one tile but has a taller height than one tile? (This tutorial is super helpful btw thank you)

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

      did you solved it?

  • @Lukas-os7nc
    @Lukas-os7nc 2 года назад +2

    Nice Episode. When I am changing the size of the hitbox from 28 to 27 the walking animation is buggy. Do you know what could be the problem there?

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

      Thanks.
      Hard to tell, you can always compare the code on github or join discord and explain your problem more in details there.

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

    Hi Kaarin, your videos are so great and clear. However I am in a problem with a difference player_sprites, can you tell me where you can edit and make your spites to a matrix of action, and how can you do that ?

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

      Thanks for the kind words. The assets are not made by me. I find them on itch.io
      If you use different sprites, the size difference will cause issues. The code is mot designed for anything bigger than the size of a tile.

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

    Thanks a lot!

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

    Hi Kaarin, first of all thank you for the content. At this very point of the tutorial I tried to add a simple png as background, but despite being relatively light (75 ko), game started to be much slower, you know why???

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

      Hey. We add backgrounds and many images in the game. Make sure you did it correctly. Take a look on github for help or discord.

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

    The player goes offscreen and get stuck in the upper black texture when I jump =/
    Edit: found the error, I typed '+' instead of '*' at 'return currentTile * Game.TILES_SIZE;'

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

    fire

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

    When I run my program and press Space, if my character hits the roof, he doesn't fall back. He stays there with a jumping animation. Never stopping or falling. Any help?
    Edit: Apparently, every time my character hits his head anywhere, he gets stuck. :(

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

      Take a look at github for the code. Most likely you missed a + or minus, or something else tiny

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

      ​@@KaarinGaming I spent a good time checking my code and didn't find the problem. So I decided to change things myself.
      The only thing I changed was
      "airSpeed = fallSpeedAfterCollision;"
      to
      "airSpeed = 0;"
      And it fixed it. However, now, for some reason, the character doesn't display the walking animation. When I press A or D, he walks, but he does the falling animation instead.
      I'm sorry to bother you or anyone that could help me. I'm really getting crazy here, you know? ;-;
      Anyhow, thanks a lot for commenting. I love that you reply to the comments, even old ones like mine.

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

      Nevermind. My "fallSpeedAfterCollision;" was equal to "0.5f - Game.SCALE" instead of "0.5f * Game.SCALE".
      The weird animation is still happening, though.

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

      Nice!
      When i got time over, i try to assist with what i can.
      Discord is also a good place to get help from. As long as you are specific

  • @Quest-Giver
    @Quest-Giver Год назад

    I also found your character will fall down as soon as you start the game by moving the check to see if the player is on the ground to just below the first moving = false; in updatePos() ^-^

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

    For some reason my character flashes, disappearing for a frame at the switch between jumping and falling animation 🤔

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

      This is because we have yet to reset the animation when switching. Comes in the next ep :)

    • @beatrizalves8461
      @beatrizalves8461 4 месяца назад

      Same here

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

    Hey me again, PROBLEM! If I change my gravity speed to be faster than my jump speed or vise versa, I lose or gain pixels when landing on a tile. I have been working on this for over a week, my brain is exploding. Even went back to simple math thinking I did something wrong but still not a clue! Hope this finds you

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

      Hello.
      Not quite sure what you mean. The default speeds are different and gravity is 0.04f and jumpspeed is -2.25f so one is faster than the other already.

  • @minotaurthegreat
    @minotaurthegreat 7 месяцев назад +1

    hello, i have a bug here
    on short, falling is overloading the running animation and it seems like there's a problem of priority? when i remove it, the overloading is gone.
    if you are still here, kaarin, i summon thee. prythee all-knowin one, bless a servant with thy knowledge!
    private void setAnimation() {
    int startAni =playerAction;
    if(moving) {
    playerAction = RUNNING;
    }
    else
    playerAction = IDLE;
    if (inAir){
    if(airSpeed

    • @KaarinGaming
      @KaarinGaming  7 месяцев назад +1

      Hey.
      Most of these issues are easiest solved by looking up the code on github :)

    • @minotaurthegreat
      @minotaurthegreat 7 месяцев назад +1

      @@KaarinGaming thank you, forgot to update the comment! actually i managed to solve the problem!

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

    Nicee

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

    Hello Kaarin, I encountered an issue where my player lands one tile higher instead of landing on the ground. I've tried reducing the size of my player sprite and that apparently worked, but I just cant get to fix it when the size of my player sprite is large. Thank you for the help in advance and great series!
    Edit: I found the fix, but now my jump animations dont work

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

      Hey I’m having the same problem here. What’d you do to fix it?

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

      @@_joselp5186 hello, I fixed this issue by scaling down my sprite and making my hitbox smaller. Apparently setting the hitbox's size larger or equal to the tile size reproduces this issue
      scale down the player hitbox smaller than the tile size itself, that fixes the issue.
      eg: tile size is of 32x32, then set your hitbox to be of around 21x25 (this worked for me)

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

      @@Meykaye Hey thanks for writing back. I did end up finding that out and scaling down. However since I’m using a different character sprite I found online he ended up looking pretty small compared to the rest of the level. Not sure if it looks bad or not. Might have to find a different sprite or just use the one in the video. Anyways thanks for the help!

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

    Make a 3D game one day pls

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

    :( How is it possible that a 30mim video becomes 2 hours

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

    I really need to catch up to you, I'm way too far behind 😵‍💫

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

      Lucky for you, the videos will stay up :)

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

    Hi Kaarin!
    First of all, this series is extremely helpful to improve in game-development! Thank you for that!
    I am currently coding it 1:1 in my project to learn how to actually code it, but I got a Problem and I don't know how to fix it:
    Sometimes (which is kinda confusing me) the KeyListener isn't registered in the start. And therefore I cant move the Player. This Problem isnt always there so Its hard to debug, cause I can't really reproduce it.
    Any Ideas?
    I already added gamePanel.setFocusable(true) before requesting the focus. I saw that in a previous episode in the Comments.
    regards ^^
    Edit:
    after joining the discord I saw I have to add the line gamePanel.requestFocusInWindow();
    I did that now. Since then it worked well. Lets see if that was the error ^^

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

    How to fix this problem:
    Exception in thread "main" java.lang.NullPointerException: Cannot load from object array because "lvlData" is null
    at utilz.HelpMethods.IsSolid(HelpMethods.java:29)
    at utilz.HelpMethods.IsEntityOnFloor(HelpMethods.java:64)
    at entities.Player.loadLvlData(Player.java:173)
    at main.Game.initClasses(Game.java:39)
    at main.Game.(Game.java:27)
    at main.MainClass.main(MainClass.java:6) ???

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

    i think i need more words to understand methods.
    GetMyOwnJavaPlatformerGameEntityYPositionUnderMyOwnJavaPlatformerGameLevelRoofOrMyOwnJavaPlatformerGameLevelAboveFloor.
    TADA!!!