Java Game Development #5 – Sprite Sheets

[ad_1]
Complete Java Game Development Course now available at my website

In this video we learn how to create sprite sheets into our game and have multiple pictures we can use while efficiently loading them. If you have any questions then be sure to leave a comment or contact me on twitter; realtutsgml. If you learned something then be sure to leave a like, comment, and favorite.

Have you ever wanted to create games? Have you ever gotten fed up with it being to difficult? Well now is the time to thank me and possibly subscribe because you have just found the channel for you! Game Maker Tutorials, Java Game Programming, Unity3D Tutorials, Batch, C++ and much much more! This is the channel for you, the one stop shop for an exploration of your hidden talent as a game developer. Unleash your potential and go wild with imagination when you finally figure out how to make any game you want!

Visit CodingMadeSimple for more exclusive tutorials and get the help you need to succeed as your very own indie game developer!

Follow me on twitter for exclusive content and interaction with me!

Game Maker Studio: Programming
Game Maker Studio: Tutorial
Java Programming
Game Programming
Game Tutorial
Programming Tutorial


Posted

in

by

Tags:

Comments

44 responses to “Java Game Development #5 – Sprite Sheets”

  1. niteskyrider Avatar

    on line 14 on the buffered image i keep getting this error come in the console
    how do you fix this?
    com.game.src.main.BufferedImageLoader.loadImage(BufferedImageLoader.java:14)

  2. Shikhar Mainalee Avatar

    WHAT? Java is free and Photoshop costs money! Does it look like everybody here has the money like you to afford and keep photoshop?

    NOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    You should have use Microsoft Paint or Paint.NET, which are FREE!

    AND IF YOUR DON'T KNOW HOW TO DO GRIDLINES ON THOSE, THEN LOOK IT UP!!!!!!!!!!!!!!!!!!!!!! YOUR THE TEACHER AND WE ARE TRYING TO LEARN WITHOUT HAVING TO PAY!!!!!!!!!!!!!!!!!!!!!

    The previous videos were pretty good, but this one is horrible so you've earned a dislike on this video!

  3. Karex_ Avatar

    Can i get that sprite sheet

  4. Hannah Mika Avatar

    11:03 he was about to type spriteShit lol

  5. Morten Hansen Avatar

    Nothing in photoshop fucking works, and regular png files doesn't fucking work either

  6. Lasitha Dananjaya Avatar

    If you use intelliJ and getting errors check this out. IT WORKS!

    http://stackoverflow.com/questions/854264/how-to-add-directory-to-classpath-in-an-application-run-profile-in-intellij-idea

    Exception in thread "Thread-0" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(ImageIO.java:1388)
    at com.game.src.main.BufferedImageLoader.loadImage(BufferedImageLoader.java:14)
    at com.game.src.main.Game.init(Game.java:33)
    at com.game.src.main.Game.run(Game.java:76)
    at java.lang.Thread.run(Thread.java:745)

  7. TRESCHK Avatar

    How to get this grid or sprite sheet? I don't have Photoshop and i don't get it in Paint.NET

  8. Marium Atta Avatar

    exception in thread "Thread-2" java.lang.Error: Unresolved compilation problem:
    IOException cannot be resolved to a type

    at com.src.game.main.Game.init(Game.java:32)
    at com.src.game.main.Game.run(Game.java:60)
    at java.lang.Thread.run(Unknown Source)
    Help? 🙂

    @RealTutsGML

  9. Voignar Avatar

    Quality tutorials, thanks man! Also I made my own sprite sheet and everyone should do it themselves instead of asking for a download. If you want to make games you should be able to make a sprite sheet on your own guys lmao

  10. Oscar Ferm Avatar

    Anyone using pyxel edit for this? can't get it to work

  11. Sadix Huseynov Avatar

    I couldn't access that image

  12. Benjamin Garcia Avatar

    You can also do (col-1)*32. I guess it's all the same though.

  13. Gameriffy Avatar

    DONT KNOW WHAT TO DO!!!!

    ———————————————

    Exception in thread "Thread-2" java.lang.NullPointerException
    at dev.gamejolt.rs.SpriteSheet.grabImage(SpriteSheet.java:16)
    at dev.gamejolt.rs.Game.init(Game.java:37)
    at dev.gamejolt.rs.Game.run(Game.java:84)
    at java.lang.Thread.run(Unknown Source)

  14. Brandon Santangelo Avatar

    Well that was embarrassing. I had the same errors as everyone else and it was an easy fix -_- One that did require some changes for netbeans but it's not too hard. Took me like 1.5hrs total to fix it. Give it a day, come back and look at it with fresh eyes.

  15. Stickimator Avatar

    I keep getting these errors at lm.BufferedImageLoader.loadImage(BufferedImageLoader.java:13)
    at lm.Game.init(Game.java:34)
    at lm.Game.run(Game.java:70)
    at java.lang.Thread.run(Unknown Source)
    can someone help pls

  16. Wily Professor Avatar

    How do i fix this error
    at java.lang.Thread.run(Unknown Source)

  17. Travis D Avatar

    Hey Guys the Null error that everyone is getting is due to not making the res folder part of the build path. Depending on the IDE you are using, it will vary how to do it. Google how to add folder to build path and your IDE name. =)

  18. LegendOfZeldaOOT Avatar

    How do I fix this error? Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!

  19. Saar Lipshitz Avatar

    Could someone link me there sprite sheet? I don't have photoshop and am really bad at drawing.

  20. FloraSora Avatar

    Here you go, guys, use this and that stupid input==null error should be gone. I honestly have no idea how they were able to make it work. I mean, it is 3.5 years old at this point, so yeah. HERE YA GO!
    P.S.: Do not forget to add the folder that contains your sprites to your Source Folder (Right Click your main project in NetBeans IDE 8.0, click Properties, then Add Folder to your "Source Package Folders.")
    //////////////CODE///////////////////
    /////////////"Game" class////////////
    public void init(){
    System.out.println("init()");

    BufferedImageLoader loader = new BufferedImageLoader();

    System.out.println("**************");
    System.out.println("File names:");
    File file = new File(".");
    for(String fileNames : file.list()) System.out.println(fileNames);
    System.out.println("**************");

    System.out.println("Trying to load image…");

    try{
    spriteSheet = loader.loadImage("res/spritesheet.png");
    }catch(IOException e){
    }
    System.out.println("Image loaded!");

    SpriteSheet ss = new SpriteSheet(spriteSheet);
    player = ss.grabImage(1,1,32,32);
    }

    //////////"BufferedImageLoader" class///////////

    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;

    public class BufferedImageLoader {

    private BufferedImage image;

    public BufferedImage loadImage(String path) throws IOException{
    System.out.println("PATH = " + path);
    File file = new File(path);
    if (file.exists()) { // First, make sure the path exists
    System.out.println("File exists!");
    }
    if (file.isDirectory()) { // This will tell you if it is a directory
    System.out.println("File is a directory!");
    }
    if (file.isFile()) { // Similarly, this will tell you if it's a file
    System.out.println("File has a path!");
    }
    System.out.println("Trying to load image:");
    image = ImageIO.read(new File(path));
    //image = ImageIO.read(getClass().getResource(path));
    System.out.println("Image path found. Returning…");
    return image;
    }

    }

  21. FloraSora Avatar

    Getting the error here that everybody else is getting… I'm at a loss right now. I've tinkered with it for 2 hours so far. Very frustrating, for a problem that seems like it should be miniscule! Granted, I am a newbie programmer, but still. Is there no help out there for us? Google garners mixed results.

  22. MataKing 12 Avatar

    I have an erore

    Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at com.game.src.main.BufferImageLoader.loadImage(BufferImageLoader.java:17)
    at com.game.src.main.Game.init(Game.java:34)
    at com.game.src.main.Game.run(Game.java:74)
    at java.lang.Thread.run(Unknown Source)

  23. Ronan Zaletel Avatar

    I get this when I try to use the BuffferedImageLoader , can anyone explain?

    Exception in thread "Thread-2" java.lang.NullPointerException
    at SpaceMain.render(SpaceMain.java:78)
    at SpaceMain.run(SpaceMain.java:53)
    at java.lang.Thread.run(Unknown Source)

  24. Sreeram Ravikumar Avatar

    Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at ShootEmup.BufferedImageLoader.loadImage(BufferedImageLoader.java:13)
    at ShootEmup.Game.init(Game.java:30)
    at ShootEmup.Game.run(Game.java:44)
    at java.lang.Thread.run(Unknown Source)

  25. Paulix00 Avatar

    the grabImage would be better if you received by parameters the img

  26. Veritas Dei Avatar

    Is it possible to use png files on desktop instead of using photoshop and spritesheet because I am having a huge problem using those..

  27. Nubbitude 'Jack' Avatar

    Damn, spent 15 mins designing my ship!

  28. Altamash Khan Avatar

    The tutorials are good, but you are explaining simple things like (try and catch) instead of trying to explain(in a better way) complex stuff like buffered image, rendering, game loop creation..etc… would be great if you could do tutorials on these topics.
    P.S : You don't even reply to the comments and help people. Not hating or anything.

  29. MrSem IsAwesome Avatar

    RealtutsGML:
    – Codes in Java
    – Has Visual C++ Express installed on PC.
    -> DAFUQ??

  30. Luki Lein Avatar

    Nice tutorials! Thanks from Germany 🙂

  31. James Meyer Avatar

    For future viewers:

    You do not need to create a sprite sheet. He's just using one for easy imports and so that he can invoke fewer methods. What's most important is that you use .png images with transparent backgrounds so that you don't wind up with a bunch of squares flying around on your screen.

    Also, when encountering errors like you'll see below, add debug scripts to your program. So in every block you ought to keep a "System.out.prinln()" method that tells the user what functions/methods/parts of the programs are running and in what order. You'll be amazed how easy it is to troubleshoot simple errors if you add a printout to each block.

  32. Arjun TS Avatar

    i get this error in the console … when i try to show my image at 100,100.

    Exception in thread "Thread-2" java.awt.image.RasterFormatException: (y + height) is outside of Raster
    at sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1248)
    at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1203)
    at com.game.src.main.SpriteSheet.grabImage(SpriteSheet.java:15)
    at com.game.src.main.Game.init(Game.java:38)
    at com.game.src.main.Game.run(Game.java:64)
    at java.lang.Thread.run(Thread.java:745)

  33. Laganstoop Avatar

    Any Solutions?

    Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at com.game.src.main.BufferImageLoader.loadImage(BufferImageLoader.java:14)
    at com.game.src.main.Game.init(Game.java:35)
    at com.game.src.main.Game.run(Game.java:73)
    at java.lang.Thread.run(Unknown Source)

  34. Manga max Avatar

    My code has never shown a black window. pastebin.com/BXE1M4fk

  35. Manga max Avatar

    How can I get the grid at 1:37 and make the brush snap to the grid? I am using Photoshop 2015 in Adobe Creative Cloud.

  36. Aiden J Avatar

    Exception in thread "Thread-0" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(ImageIO.java:1388)
    at com.game.src.main.BufferedImageLoader.loadImage(BufferedImageLoader.java:14)
    at com.game.src.main.Game.init(Game.java:33)
    at com.game.src.main.Game.run(Game.java:76)
    at java.lang.Thread.run(Thread.java:745)

  37. Aiden J Avatar

    I DON'T KNOW HOW HE CAN MAKE THAT GRID AT 1:37!!!! PLEASE HELP ME OUT….. I'm using photoshop 2015 trial version

  38. ben davey Avatar

    cant find where to save the image to and it is really annoying it wont show up in my computer

  39. Darragh Walsh Avatar

    Best java series ever

  40. Alex Sere Avatar

    some thing is happening to me, the black background does not appear

  41. Lt Lobster Avatar

    Where can I get the source code?

  42. Nick Nicholas Avatar

    Exception in thread "Thread-2" java.lang.NullPointerException
    at SpriteSheet.grabImage(SpriteSheet.java:14)
    at Game.init(Game.java:42)
    at Game.run(Game.java:72)
    at java.lang.Thread.run(Unknown Source)

  43. Anthony Awuzie Avatar

    i don't have photoshop and but i just downloaded paint.NET and i cant do that draw the space ship with it pls help

Leave a Reply

Your email address will not be published. Required fields are marked *