ANIMATIONS - Episode #05 - Platformer Tutorial Java

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 98

  • @KaarinGaming
    @KaarinGaming  2 роки тому +34

    Hey Guys! Welcome back.
    The last episode wasn´t my best work. Felt like the overall quality was not very high. But, i try to improve and i hope this one can make up for it.
    The intro is stupid i know, but i loved it, had to keep it xD
    Enjoy!

    • @bryceblazegamingyt9741
      @bryceblazegamingyt9741 2 роки тому +8

      I believe that last episode was great! I don't think you have to be so hard on yourself :D

  • @Voidheartz
    @Voidheartz 2 місяці тому +2

    Grym video! Väldigt lärorik för nån som är ny. Keep it up:)

  • @bryceblazegamingyt9741
    @bryceblazegamingyt9741 2 роки тому +15

    Oh wow! I wasnt expecting to actually be in the video, thanks!

    • @KaarinGaming
      @KaarinGaming  2 роки тому +6

      Give credit where credit is due ;)

  • @kalugabro
    @kalugabro 5 місяців тому +2

    still an amazing tutorial years later, will be finishing the whole series and liking every episode. Love your pacing and explanations. ❤❤

  • @notsospecialised
    @notsospecialised 3 місяці тому +2

    absolute legend

  • @trungnguyen-nl4fx
    @trungnguyen-nl4fx 3 місяці тому +2

    I like your videos so much. They help me a lot that now I can understand the basic concepts behind the sense. It would be extremely good if you can sometimes resonate why choosing something to handle is the best fit in situations. Thank you and hope for your new videos :)

  • @anubhavjha7704
    @anubhavjha7704 6 місяців тому +5

    When we switch the animation, its better to reset the animationIndex back to 0, otherwise it causes the image to flicker. For example the running animation has 6 frames and suppose we are moving, and stopped when the running animation was at 6th frame. The playerAction will instantly change to IDLE but what about the animationIndex? This will cause a blank subImage to be rendered. Here is my approach for fixing it:
    private void setAnimation() {
    if (moving) {
    if (playerAction == IDLE) {
    animationIdex = 0;
    playerAction = RUNNING;
    }
    } else {
    if (playerAction == RUNNING) {
    animationIdex = 0;
    playerAction = IDLE;
    }
    }
    }

  • @Mohsirk36_79
    @Mohsirk36_79 Рік тому +10

    Your tutorials are really great and the way you teach from scratch is satisfying and logical. you are doing great work. Could you keep it up?.

  • @SimplyFN-1
    @SimplyFN-1 5 місяців тому +1

    case RUNNING:
    return 6;
    case IDLE:
    return 5;
    case HIT
    return 4;
    case JUMP:
    case ATTACK_1:
    case ATTACK_JUMP_1:
    case ATTACK_JUMP_2:
    return 3;
    case GROUND:
    return 2;
    case FALLING:
    default:
    return 1;
    i got you bro❤

    • @SimplyFN-1
      @SimplyFN-1 5 місяців тому

      package utils;
      public class Constants {
      public static class PlayerConstants{
      public static final int RUNNING = 0;
      public static final int IDLE = 1;
      public static final int JUMP = 2;
      public static final int FALLING = 3;
      public static final int GROUND = 4;
      public static final int HIT = 5;
      public static final int ATTACK_1 = 6;
      public static final int ATTACK_JUMP_1 = 7;
      public static final int ATTACK_JUMP_2 = 8;
      public static int GetSpriteAmount(int player_action) {
      switch(player_action) {
      case RUNNING:
      return 6;
      case IDLE:
      return 5;
      case HIT:
      return 4;
      case JUMP:
      case ATTACK_1:
      case ATTACK_JUMP_1:
      case ATTACK_JUMP_2:
      return 3;
      case GROUND:
      return 2;
      case FALLING:
      default:
      return 1;
      }
      }
      }
      }

  • @devnull711
    @devnull711 2 роки тому +8

    Hello, I really like this tutorial series. I am a Java developer for many years now but I never did any gaming/advance UI stuff and I really like you content!
    Please note that you have something of a bug, meaning the paintComponent() method should have requestFocus(true); in it, or else on my local machine it would lose focus about 1/4 of the times.
    Also consider adding private constructors to your constant classes :)

  • @michaelbigam3253
    @michaelbigam3253 Рік тому +4

    Your videos have been amazing!, thank you for putting these out there. I have honestly learned so much :)

  • @jeet_thakur-a08
    @jeet_thakur-a08 Рік тому +2

    wow, your tutorials are just amazing, you helped me a lot 💕

  • @herbst2941
    @herbst2941 Рік тому +1

    Thanks for another great episode!

  • @calebkrauter4027
    @calebkrauter4027 2 роки тому +2

    This is so helpful. Thank you!

  • @tron1kk
    @tron1kk 2 роки тому +2

    Yo, man!
    You make super cool content!
    Thank you very much for such a detailed and exclusive review! Good luck in future career!=)

  • @murilodutra8569
    @murilodutra8569 5 місяців тому

    Obrigado pela aula paizao, tmj!

  • @IapetusRetroStuff
    @IapetusRetroStuff 2 роки тому +14

    Great tutorial series, congrats. One questions, couldn't you use ENUM instead of those classes with constants?

  • @aladin7339
    @aladin7339 2 роки тому +1

    Epic, as always

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 роки тому +1

    Thanks!

  • @dylanroman7738
    @dylanroman7738 Рік тому +4

    Great video, you teach better than my teacher xd

  • @thatnelfy
    @thatnelfy 2 роки тому +1

    ty for great video! :)

  • @lunasoldev
    @lunasoldev 10 місяців тому +1

    Nice video, am just curious why you didnt use enums for the constants as it would've been a lot simpler

  • @pstlvictoras
    @pstlvictoras Рік тому +1

    this channel is something else man, thank you for all of this great things Jesus, can believe I found you, how should I practice all of these for being good as you are? :D

  • @templeOfChrist1994
    @templeOfChrist1994 2 роки тому +3

    That was fast :P

  • @Mohammedatiqulrub
    @Mohammedatiqulrub 7 місяців тому

    hello @KaarinGaming , at 4:18 seconds , how did u get the x,y,width, height as i.
    we have declare a variable right and initialize . if i do that then the in the for loop it shows error and asks me to rename the the i in for loop . please help at the earliest

  • @Meykaye
    @Meykaye Рік тому +2

    Hey @KaarinGaming, your tutorials are amazing, but I have an issue when it comes to adding animations. When I try to run the program (at around 11:27), I get an exception -> Exception in thread "main" java.awt.image.RasterFormatException: (x + width) is outside of Raster. How can I resolve this? Thank you in advance.

    • @KaarinGaming
      @KaarinGaming  Рік тому +1

      Hello.
      This error means you are trying to get a pixel outside the bounds of the image.
      Recheck the code and math.
      Cheers!

    • @Meykaye
      @Meykaye Рік тому +1

      Hey@@KaarinGaming, thank you so much for the reply! I finally got it to work, I reversed the dimension values by mistake and thus granted exceptions in my code. Thank you so much once again for your help.

  • @JuvertAlexisDulay
    @JuvertAlexisDulay 11 місяців тому +2

    what i'm gonna do when the IDLE part is not working

  • @Mohammedatiqulrub
    @Mohammedatiqulrub 7 місяців тому

    hello sir at 11:03
    animation[j][i] - in this line it shows j cannot be resolved to variable . how do i fix this . please let me know at earliest

  • @rajarshidutta1376
    @rajarshidutta1376 Рік тому +1

    Excellently helpful and extremely well structured course! But, where did you get that set of images? Did you draw it anyway or collected from any web source? After finishing this course I have planned to clone one of my favorite childhood games, which names 'Shark Attack'.. so I was wondering if I could get any website on the internet which provides some tool to create this kind of images with which we can create any (if not 3D, then 2D) animations we want. Can you tell me about any resource like that?

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Thanks for the kind words! :)
      There is links in description where and what I use.
      Most of your needs can be found on itch.io

    • @rajarshidutta1376
      @rajarshidutta1376 Рік тому

      I saw they sell games.. I wanted a tool to build up animations as game engines like Unity are too heavy for my computer.. Anyway, how about you make a tutorial on creating 2D models in a game engine and show how to integrate those models with our java code?

  • @sowmikroy2251
    @sowmikroy2251 Рік тому +2

    i have a problem!
    if i start spite moving it just moves. it doesn't stop(idle state)
    what is the problem ? how can i stop him moving?
    27:07

    • @monikavarma757
      @monikavarma757 2 місяці тому +1

      YEAH PLS HELP SOMEBODY !!!!

    • @monikavarma757
      @monikavarma757 2 місяці тому

      hey there, I think you might have written....'key pressed' contents into 'key released '.
      I had same bug. Ugh actually , my dumbself caused it but, hey I solved it too! so it's okay!🥲...so it could be the same case to yours. Hope it helps!

  • @felipegomes2263
    @felipegomes2263 2 роки тому +2

    I'm getting an error at the switch inside the updatePos() function, it just says "duplicate case". I don't know why.
    Also, why you have Game class imported inside KeyboardInputs? If I do Import, I get the yellow mark saying it's not being used for anything but yours don't.
    Edit: I figure, I forgot to set the up, right, down constants to 1, 2 and 3 respectively. They were all with value 0... oh well, moving on.

  • @slndiilszneiei1547
    @slndiilszneiei1547 7 місяців тому

    I downloaded the png file on your page, but the animation does not work for me. It looks fixed like a picture.What do you think is the reason?

  • @annguyentruong1050
    @annguyentruong1050 7 місяців тому

    Thanks for your video. It's very great. but i have a question.I have idle animations divided from 1 to 25. How can I merge them into one image like player_sprites.png?

  • @christianjaycaburnay
    @christianjaycaburnay Місяць тому

    where can i get the sprite images?

  • @sabNavyA
    @sabNavyA 2 роки тому +3

    I'm running into a problem where if I release the key at the end of the player's animation, they flicker as if their last image is blank, but when I hold the key, the animation plays without flickering.

    • @KaarinGaming
      @KaarinGaming  2 роки тому +3

      That's because when you change the animation, you never reset the index and animation tick to 0.
      We will take care of that soon =)

  • @zeudev
    @zeudev Рік тому +2

  • @Isma7123
    @Isma7123 Рік тому +2

    I have a problem where the sprite doesn't move, it plays the animation but it just doesn't work
    EDIT: nvm, in the setDirection method instead of updating the playerDirection i instead updated the player action, mb.

  • @rezarg
    @rezarg Рік тому +2

    Any reason why you spelt it Utilz and not Utils?

    • @KaarinGaming
      @KaarinGaming  Рік тому +2

      I think it was to avoid naming it the same as other libraries in java.

  • @nunya2122
    @nunya2122 Рік тому +1

    I love this but I am trying to apply this method to a larger sprite sheet and I have no idea how to make the calculations work for it. Any tips?

    • @KaarinGaming
      @KaarinGaming  Рік тому

      You need to consider the size of each sprite, amounts of animations and the amount of sprites per animation.
      Worth mentioning that collisions only work (in this code) for hitboxes smaller than a tile.
      Good luck

  • @mr.zenitsuagatsuma
    @mr.zenitsuagatsuma Рік тому +1

    ive lost all of my code due to a bug. any suggestions what i should do now. any how your vids are great

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Shit happens.
      All the code can be found on github. All you have to do is to start where you were before. =) Each branch is its own episode.

    • @mr.zenitsuagatsuma
      @mr.zenitsuagatsuma Рік тому

      @@KaarinGaming thanks bruv

  • @中文中国-t4u
    @中文中国-t4u 11 місяців тому

    The first time it worked well but after rerunning program it doesn’t move when I click on keyboard 😢

  • @BeastRavagerOrdinary
    @BeastRavagerOrdinary Рік тому

    Sir this error resolved but can you tell me why any animation is not working

  • @BeastRavagerOrdinary
    @BeastRavagerOrdinary Рік тому +1

    Your vedios are amazing i watch it everyday but its a error of IO Exception

  • @Ganiovi
    @Ganiovi Рік тому

    Hi! How did you save the icon image for a player on each row and column? On my PC, the image is moving on the left and right side and is not in the same place to see just the character moving

    • @romi2418
      @romi2418 Рік тому

      this happens if your dont give the right size of the sprite image.(Thats how i fixed it)

  • @FerodriEste
    @FerodriEste 2 роки тому +1

    Hello Kaarin.
    I don't know why when I run the project sometimes I can move the character and other times I can't... I can't find the problem

    • @KaarinGaming
      @KaarinGaming  2 роки тому

      Hey.
      Check out our discord server for troubleshooting and post your code question there =)

  • @BeastRavagerOrdinary
    @BeastRavagerOrdinary Рік тому

    Can you tell me why any animation is not working

  • @ducklacanard
    @ducklacanard 2 роки тому +1

    I've noticed a problem. When I try to move my sprite with keyboard ( I removed mouse controls 'caouse I don't want'em ), I have to do it immediately after my game launches, becaouse when I do it like a second after it launches, it won't do anything, at least I won't see it maybe it moves but repaint does not work?

    • @ducklacanard
      @ducklacanard 2 роки тому +1

      Sometimes it doesn't work at all

    • @KaarinGaming
      @KaarinGaming  2 роки тому +2

      Hey.
      Add gamepanel.setfocusable true before request focus
      Its a bug we fixed a few episodes back

  • @thepurplemug
    @thepurplemug 2 роки тому +2

    Sometimes I play the program and it works. Then, without changin a thing, I play the program again and it doesn't get the keyboard inputs... can someone help me with that?

    • @KaarinGaming
      @KaarinGaming  2 роки тому +3

      Yeah its a issue we fix longer down the road.
      But put gamepanel.setFocusable(true) before calling .requestFocus();

    • @thepurplemug
      @thepurplemug 2 роки тому +1

      @@KaarinGaming Thank you very much!

    • @tron1kk
      @tron1kk 2 роки тому

      @@KaarinGaming Bro, could you tell me please in which video this problem is solved?

  • @nabman5619
    @nabman5619 Місяць тому

    Hate seeing ads? Forced to watch an ad.

  • @mathewbarber7103
    @mathewbarber7103 Рік тому +1

    can anyone tell me where to find the character sprite please? I've tried other but just keep messing up the numbers

    • @KaarinGaming
      @KaarinGaming  Рік тому +1

      The code and the assets can be found both on my website and github. Links are in the description :)

    • @mathewbarber7103
      @mathewbarber7103 Рік тому +1

      @@KaarinGaming thank you so much I've found them on your site

  • @robertl.2848
    @robertl.2848 Рік тому +1

    Hello, great video, but I have a little problem:
    For some reason, my game speeds up after a certain time. I also noticed that my animation and moving speed are slower than yours. Then, after running the program for a few minutes, the game speeds up, and everything becomes faster.
    Can anyone help?
    edit: It also seems that the movement is not smooth. In an earlier video, you said that this is caused by the repaint() loop and that the thread loop would fix this problem. But it seems that I still have this problem.

    • @KaarinGaming
      @KaarinGaming  Рік тому +2

      Hey. Does not sound like its working correct. Make sure to take a look at github for code and then there is always a discord server to check out for more help. Usually its some small bit missing in your code. :)

    • @robertl.2848
      @robertl.2848 Рік тому +1

      @@KaarinGaming Hey thanks for the quick response. I compared my code to the one on github but everything looked fine. Maybe it has something to do with my PC, maybe it's just processing it slower first and then catches up. In Unity Time.deltaTime is used for the speed of movements, to maintain a consistent speed, regardless of the system the game is played. Do you implement something similar later in the tutorials?

    • @KaarinGaming
      @KaarinGaming  Рік тому +1

      Np.
      The game is far to simple as of now to make the game lagg or so.
      Could just be the same issue I faced while developing. Long story short, it goes to fast. So it laggs. When we add the level it went away. It was a linux thing for me.
      Regarding the delta you speak of, something similar is added.
      We don't use delta time, but we do store past time to make sure the game can "catch up".
      It comes in ep 7 or so when we fix the game loop.

    • @robertl.2848
      @robertl.2848 Рік тому +1

      @@KaarinGaming Ok. I have continued with the tutorials and after implementing Loop 2.0 the problem now apparently has gone away. Thanks again for the response.

  • @victorpd6172
    @victorpd6172 Рік тому +1

    Hello, at this point my game is already laggy, especially when I move the playe with the keyboard. I've 100% of CPU usage in one of the threads. I have played Red Dead Redemption 2 on this PC so I think it should be able to handle this game. Any ideas?
    EDIT: I noticed that even when I'm not pressing any keys one CPU core goes up to 100% usage, so probably not a Keyboard Input problem.
    EDIT: The game is working fine in Windows but not in Ubuntu, maybe a JVM problem?

    • @KaarinGaming
      @KaarinGaming  Рік тому +1

      Hey. This will go away. ( if it is what I am thinking of)
      It's a thing with Ubuntu/linux.
      It goes to fast in simple words.
      If you were to create a 100x100 (or bigger) grid of white squares behind it all. Just to give the program some extra "to do" while looping. It should go go away. (I did this when recording episodes at times because the issue were in Linux)
      But once we add more things, the level, especially, it should go away.
      If you move your mouse around the window it does not lagg?, but once you stop, it starts to lagg again.

    • @victorpd6172
      @victorpd6172 Рік тому

      @@KaarinGaming It seems that when I move the player, the performance is better than when its idle.

    • @victorpd6172
      @victorpd6172 Рік тому

      @@KaarinGaming I will continue with the next episodes then...

    • @wienergames2293
      @wienergames2293 Рік тому

      For other people with the same problem, simply adding:
      Toolkit.getDefaultToolkit().sync();
      after
      gamePanel.repaint();
      should fix the problem.

  • @hdteachesmath8784
    @hdteachesmath8784 9 місяців тому

    What to do if it is not moving and the code is also correct

    • @hdteachesmath8784
      @hdteachesmath8784 9 місяців тому

      found the problem

    • @hieudo925
      @hieudo925 8 місяців тому

      @@hdteachesmath8784 sir, help me out, I cant move the character, and the only thing working is the animation

  • @nikoman4785
    @nikoman4785 Рік тому

    can someone explain why the hell am i getting an error "case expressions must be constant expressions" im so fucking mad at this

  • @CheckMeOut891
    @CheckMeOut891 2 роки тому +1

    your sprites are not on your website or github.

  • @senaol
    @senaol 2 роки тому +4

    I like your tutorials. Thank you.
    Let me suggest my piece of code.
    public enum PlayerState {
    IDLE(5), RUNNING(6), HIT(4);
    private final int spriteAmmount;
    PlayerState(int spriteAmmount){
    this.spriteAmmount = spriteAmmount;
    }
    public int getSpriteAmmount(){
    return this.spriteAmmount;
    }
    }

    • @KaarinGaming
      @KaarinGaming  2 роки тому +1

      Cheers man!
      Yeah, I will use enums more in the future.