r/javahelp • u/TheimmortalGuyofDoom • Sep 20 '20
I'm an Beginner in Java, and I wanna program a small 2D Game one day. Whats the easiest way to learn it?
Especially I wanna learn how to design GUI's and how you use Images and let them interact with each other. Does someone now a good Tutorial or sth. else?
2
u/dionthorn this.isAPro=false; this.helping=true; Sep 20 '20
Here is my open source pure OpenJDK OpenJavaFX game project on github:
https://github.com/dionthorn/2DTacticalRPG
Feel free to clone it, mess with it, whatever you want really.
2
u/TheimmortalGuyofDoom Sep 20 '20
Wow, that's a really cool game your working on! I'll definitely look into the code to learn some things, but I don't wanna copy it. But it looks good, stay tuned!
3
u/dionthorn this.isAPro=false; this.helping=true; Sep 20 '20
For a minimal example of running JavaFX I have a small package included:
Run_Minimal is the minimum environment I use while Run and Light are used to demonstrate how to use javaFX to 'animate' lights on the canvas.
8
u/firsthour Profressional developer since 2006 Sep 20 '20
Check out libgdx for sure.
7
u/Sequel_Police Sep 20 '20
Op, this is the correct answer. The things you learn will translate well in the future, and libgdx has good abstractions. Do not use JavaFX.
4
u/neck_crow Sep 20 '20
But takes care of the difficult things, which, in my opinion, makes using those libraries harder. In the first game I created, I built the game loop, image manipulation, etc. from scratch, and learned so much more about how games work, despite the fact my implementations were suboptimal.
4
u/dionthorn this.isAPro=false; this.helping=true; Sep 20 '20
That's how I felt after I made my TileSet class lol. Sure I could've found a pre made method for it but those 2 hours of work felt super good after everything was working.
https://github.com/dionthorn/2DTacticalRPG/blob/master/src/main/java/org/dionthorn/TileSet.java
3
u/neck_crow Sep 20 '20
I completely agree. Building an image rotating algorithm that finally worked felt amazing. It took 2 weeks of research and work to make one that I could implement into my thing.
I have to give up on the pathfinding part, though. I know now I could have implemented A*, but that’s just hindsight.
2
u/dionthorn this.isAPro=false; this.helping=true; Sep 20 '20
ya I'm dreading the day I actually need to implement real path finding rather than
Try to move randomly 10 times if not just pass1
u/Sequel_Police Sep 20 '20
Trust me, I feel you. The old C dev in me wants to say go learn how to actually write the whole thing from scratch. But, Java being Java, the abstraction is pretty normal, and IMO libgdx is still low-level enough compared to Unity, but way more appropriate than another Java option, short of going straight for LWJGL.
3
u/reandoro Sep 20 '20
LibGDX if you want to get into java game development. JavaFX if you are more interested in learning GUI.
3
u/gameMaker203 Sep 20 '20
I was able to make snake and then a shitty non working chess game it's def hard. I just used javafx I think
7
u/Kallory Sep 20 '20
JavaFX game tutorial brings up a host of options on YouTube.
However, I think you should learn the basics of javafx and then attempt to create a game prior to following a tutorial
3
2
u/bentheone Sep 20 '20
What you specifically want to look up is the Canvas class of JavaFX. Its the object that lets you display shapes, images etc..
Javascript+html5 has the almost exact same thing, same name, same logic.
And if Games are what you want to do you can check the Nature of Code by Daniel Schiffman. Its a book, a website and a huge YouTube channel that specifically teaches what you need to know as a beginner. Its really good. It uses Processing, which is a Java library.
-4
Sep 20 '20
Don't use Java and on't build games from scratch - for beginners.
Use some development platform!
8
Sep 20 '20
[removed] — view removed comment
3
3
u/Kambz22 Intermediate Brewer Sep 20 '20
Java is fine for 2d games and even not insanely complex 3d games.
It used to be a much bigger issue, but since everyone seems to have 32gb of RAM, insane fast CPUs, and SSDs, its not nearly as bad as it used to be. There's more than enough fire power to blast through the lack of memory management. (I wouldn't recommend Java for a large game you want to publish, but as a personal side project to start, I honestly think its the perfect start)
8
u/sinistergroupon Sep 20 '20
Start with the basics before you move to anything GUI or Game related.