Advertisement

What rendering tool to use

Started by September 09, 2016 10:13 PM
2 comments, last by Whiskydog 8 years, 2 months ago

Hello,

I'm making a game in Java. I'm using JPanels and some other shapes to render my stuff. The problem is that the drawing and loop are not the best for games, sometimes I see the performance drop a little. Thanks to my bad programming habits, I didn't separated the logic of the game from the rendering stuff, so now I have thrown everything away.

I am going to make the game from scratch again, but this time I want to do things correctly.

What tools can I use to render my game? [2D Game, rendering sprites]

And the advantages of using that specific tool?

I have found several tools, but I still feel confused and afraid to invest my time without asking for opinions first.

I didn't separated the logic of the game from the rendering stuff
This is great progress!

I know, when you reach the point where you realize "oh no, I made a huge mistake three weeks back, and now I have to change everything", it doesn't feel like great progress, but it is.

You learned the importance of keeping rendering separate from the game logic. You won't make that same mistake again. That's the big progress you made. It will save you months to years of coding in the future.

so now I have thrown everything away
Ha, I used to do that too, it feels like a total failure, get rid of it :)

Nowadays, my habits are less drastic. The point is, that besides that one big mistake, you also made a lot of good decisions there. I usually leave the code alone for a few days (I am too angry about it to make sane decisions otherwise). After some days I have cooled down enough to have another go at it. If you use version control, you can go back in history, and find the spot where you made that error for the first time. If you don't use version control, make a new directory, and copy the bits of code that are not involved in the problem. A third approach is to make a copy of your code, and comment all broken parts out, but that doesn't really work for me.

Now you have the new program that partly works, and the broken program that has bits and pieces of functionality that the new program does not have. The next job is to take the good bits from the broken program, and put them in the new program in the right way. I usually just write the code anew while looking at the old code. Basically, it's salvaging the useful bits of the old program, while writing new pieces, avoiding your previous mistake. In your case, you could rescue the auxiliary code (loading sprites for example), and the pure rendering bits and pieces, probably in a new structure that you have to invent first. The idea is that you did a lot of thinking behind each line of code, by doing copy/paste of the good lines, you're saving yourself the effort of doing that thinking again.

For completeness, there is another way to do the above. It's called refactoring. Your program is working, but the structure is wrong. Refactoring is changing the structure of the code such that before and after the change everything works in the same way, but with a better structure. The approach here is usually to slowly separate the game logic from the rendering by making small rewriting steps. Before and after a step the code all works, but after each step, the game logic is a bit more separated from the rendering than before. By doing that often enough, you can fix your mistake, while the program continues to work.

It's a more difficult skill, but very useful to have!

I am going to make the game from scratch again, but this time I want to do things correctly.
I also aim for that each time, but it hardly ever happens. Problem is that we make tens of decisions in each line of code, and we are far less perfect than we like to believe. It's a matter of time until you make a wrong turn somewhere, at least I never wrote a program without error in it, beyond the "hello world" scale of programs (and even there, I am very capable of making a typo in the message :p ).

Don't be afraid of errors. You cannot avoid them, programming is a complex activity, and you're not a computer that doesn't make mistakes[1]. Instead, learn how to cope with errors without losing a lot of time.

As for tools, I am not sure. I hear people use libgdx, but I know nothing about it. Perhaps other people will provide you with other suggestions.

One thing to keep in mind is that a new tool will not reduce the complexity of programming. If you know how to use the tool, it will probably help you, but if you don't know the tool, you move from 1 problem (programming the game) to 2 problems (programming the game, and understanding the tool). Adding problems to your plate will at least not make things quicker. It will also not eliminate errors.

However, check it out. Have a look at the tool, ignore all the fancy pictures and marketing stuff. Look at the documentation, try it for say a day to a week. If you feel comfortable in it, it may work for you.

[1] And even computers do make mistakes. There are error rates of CPUs. They are very low, but not 0, so every now and then, even the CPU messes up :)

Advertisement

If you want something low level, you can take a look at LWJGL bindings for Open GL. Other options are LibGDX, as suggested above, or Slick2D. As far as I know, both of them use LWJGL underneath.

About the advantages of each tool, I'm honestly not sure. All of them are good options for a 2D game, I would just look at the examples and try out anything you think you would be comfortable coding with. A quick search in Google and Stack Overflow shows an order of magnitude more results for LibGDX than Slick2D, so that's a point for LibGDX.

If I were to make a game with Java, I would probably start with LibGDX, but my only reasoning is that I've already used it and is very nice and seems to have a bigger community that the other options I'm aware of.

Yeah I started making games in Java after reading +500 pages of Head First Java (and ~1.5 year of previous learning on C and messing with Unity), and soon realized that Swing is not meant for games too much. Now I'm using libGdx, made a Blackjack game with dealer and split and stuff, then a local-multiplayer TicTacToe. Now I'm trying to make an Isaac-ish 'thing' but I'm kinda stuck.

But yeah my point is that libGdx definetly has some power in it! And when it comes to learning libGdx itself is not that big of a deal at least for me. Besides the documentation, tutorials and Questions&Answers about it are pretty solid and abundant like Avalander says.

I found myself stuck more in how to structure my game (where to handle Animations and Input, "what should go really in the Player class?", "is an enemy entity collection the way to go?") than learning libGdx 'shenanigans'.

This topic is closed to new replies.

Advertisement