Alright so I was wondering how would you begin to develop a library around a game. I understand what a library is, but I’ve never attempted to make one. So how would you start off with making the window in the library so you can easily call it in your game without all the lines necessary to make a JFrame or what ever you needed. Hopefully that makes sense and maybe you clarify how simple it maybe, I usually over think things.
A library is more or less a set of tools meant to help you make games quicker. For example
- reading XML files
- getting access to OpenGL (LWJGL, JOGL)
- handling game objects
- handling game menus and UI
- a full game engine
With a game engine you don’t have to code so much since the engine handles most of it. You pretty much only have to code things like game logic. The real work is filling the engine with content (images, menus, textures, 3D models, game logic, game content (items, skills, etc)). A game engine often comes with things like level editors and other editors for creating resources usable by the engine. Usually, the easier an engine is to use the more limitations there are. For example, a 2D game engine can’t handle 3D graphics but is obviously simpler to use. Sometimes an engine allows you to work outside it or extend it, for example like how it’s possible to do normal OpenGL calls while using Slick2D to do any kind of rendering (3D or 2D) you want.
Making your own complete game engine is a pretty bad idea in my opinion. It’s a lot more work than most people think, especially the surrounding tools and deciding which features to implement, and in the end you might realize that it’s not exactly what you wanted. You’ll also not end up with a complete game, just an engine so the “reward” for your work is pretty much just the ability to make a game (hopefully) quicker than before. The chance that someone else is going to base their game on your engine is also pretty much 0 since not many people are willing to bet on a new unproven game engine.
I’d instead encourage you to write much smaller “libraries” for personal use. In other words write reusable code. I have a voxel renderer which I could easily use/modify to render a Minecraft world file (if I knew how to read a Minecraft save file that is ;)). I have a threading library I can use to multithread my games. I have a few classes abstracting things like OpenGL textures, tiled images, shaders, 3D cameras, etc. I have a frustum culler that can be used to check if objects actually will end up on the screen. I have a few pathfinding algorithms implemented, a fog-of-war renderer and some GUI stuff using TWL.
Many things can be shared between games that seem to be very different. A 2D strategy game needs pathfinding for the units, but so does a 3D first person shooter for AI controlled players. The same pathfinding “library” can be used in them if they’re written correctly or with just slight modifications. Building up a bag of tools will help you make games quicker, but of course don’t just make tools all day. Make them as you make games. Again, just write reusable code.
In short.
Generalize everything.
Thanks for the replys, I understand that theagentd. Could you give me an example of a library that just holds making a JFrame ?
JFrames usually aren’t used for games since they actually pop up in a new window, which won’t work in fullscreen and looks kind of lame for a game. Usually people implement some kind of GUI over the graphics library they use (usually either Java2D or LWJGL). Swing is based on Java2D so it is possible to implement a GUI with Swing components if you change some settings to it to use active rendering. LWJGL is trickier but there exists a powerful GUI library called TWL that I’ve been using for a while. It’s pretty difficult to use due to the lack of documentation, but still easier than writing your own GUI. It’s a very powerful library, supporting custom XML theme files and all which makes it a bit hard to use. There’s a good subforum for it in the Slick2D forum though where the creator answers your questions within hours, which I have to give him credit for!
You say JFrames aren’t usually used for games? What do you recommend then? An Applet?
Sometimes a skeleton could be mistaken as library.
No, listen… How many games pop up a real Windows window that appears on the task bar and can be minimized and maximized? It’d be so weird. The window could end up behind the game window!
Instead you could add for example a custom JPanel which overrides the paint() method to draw your inventory in it. You could also add a MouseMotionListener to it to implement the ability to drag it around manually. That way your inventory “window” is always on top and can be transparent and everything, since it’s actually not a “real” window, just something drawn on top of the game.
Ok, you confused me. I am using all that, this is not my issue. Stated in the first post. Thanks.
Oh, right, sorry. I meant that they don’t use Swing JFrames for in-game windows. Sorry about that.
Yes, you mean like adding a JPanel to it and painting to that component, right? If not please explain, thank you.
Exactly.