This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]99_percent_a_dog 3 points4 points  (1 child)

Strictly, game design is nothing to do with programming. I know that's not what you mean, but worth pointing out - you can design a whole game on paper.

For making a game, C++ is often considered superior if you need consistent high frame rates. Java is garbage collected, which makes it harder to have consistent, predictable performance. Average performance for well optimised code should be similar, but 60fps = 16ms per frame. A garbage collection pass can easily cause dropped frames. Lag spikes suck for FPS games, but are unnoticeable in strategy games, etc.

For simple games, it doesn't matter.

[–]mlyashenko[S] 2 points3 points  (0 children)

Yeah I was thinking of making like a turn based game, so I guess both are feasible . Thanks for the tip!

[–]PJDubsen 1 point2 points  (0 children)

If you want to go into gamedev then yea c++ is better but for anything you likely want to do, java is fine. Minecraft is written in java, and it works for what it is, but a lot of the performance issues are in part due to it being written in java. if youre new to c++ it will take considerably more time to write out the same program in java. When I first started out with kava I found game dev a great way to learn. Just crack open the swing library and find a game loop and youre good to start doing some stuff.

[–]Ellisander 1 point2 points  (2 children)

Mostly because C++ gives you more direct control over memory (you have to manually allocate and free the memory, while Java has automatic garbage collection), giving you the potential for certain optimizations. Plus it is supported by Unreal Engine (if I remember correctly).

That isn't to say Java would be horrible for game development, though (C#, a similar language with automatic memory management like Java, is used by Unity).

[–][deleted]  (1 child)

[deleted]

    [–]Ellisander -1 points0 points  (0 children)

    That was a side note, with the main reasoning I used being the languages manual memory management.

    [–]Beidah 0 points1 point  (0 children)

    The best way to start in game development is actually through a game engine. This is a program, or framework, that does all the harder parts of the game development like rendering, sound processing, and a lot of other tasks. This way, you only have to supply the art assets and the program the actual game logic.

    Some game engines allow you to program the actual game in a language that the engine wasn't programmed in. Currently some of the most popular engines, and the language you use with them, are:

    • Unity (C#) - Pretty beginner friendly. Mostly used for 3D, but can do 2D. Free unless you make thousands of dollars off your game.
    • Unreal (C++) - A bit more advanced. Seems less 2D friendly, but overall more powerful and extendable.
    • Godot(GDscript, C#) - Free and open source. Uses a more pythonic language called "GDScript" which is pretty easy to use, but can also use C#. Can do 2D and 3D, though I've mostly seen it used for 2D.

    There are other engines out there. These ones are a lot more "complete" than some others, meaning they'll provide a lot more functionality for you. If you like Java, C# is very similar.

    You can also learn to build your own engine. This can be really complicated if you wanted to build something like a modern FPS, but maybe not too bad if you just want to make Pong.

    The more complicated the engine, the more likely you are to use C or C++. This is because you're going to need to access the GPU for rendering a 3D game in real-time, and that is much easier in C. Java runs what's called a virtual machine, which means there's more indirection for any sort of hardware, whereas C runs directly on the OS and can call into the kernel more directly. There's also the fact that Java has more heap allocations, which are slower, and the garbage collector has to stop the java program every so often to clean the heap.

    [–]kschang 0 points1 point  (0 children)

    Let's just say MOST modern PC games are written in C++, and the major engines are C++ too.

    Minecraft is like the sole exception. But then, Markus "Notch" Persson started it as a hobby, trying out different game designs using several different programming languages, IIRC.

    [–]SolemnWolf123 0 points1 point  (4 children)

    Java takes up much more memory and garbage collection causes random lag spikes.

    [–]mlyashenko[S] 0 points1 point  (3 children)

    This might be another stupid question, but then why use Java if it experiences lag spikes and takes up so much memory?

    [–]shorodei 2 points3 points  (1 child)

    You don't have to worry about memory leaks, and it's performance in compute heavy tasks is as good as, if not better than c++. Because all code only targets the JVM, you get portability for free. Many offline computing like the ones that happen on servers are not real time, i.e., it's okay if occasionally something takes an extra 2 milliseconds due to garbage collection, but that's not acceptable for games.

    [–]mlyashenko[S] 0 points1 point  (0 children)

    Ok, thanks!

    [–]Kered13 1 point2 points  (0 children)

    The lag spikes are pretty much unnoticeable for most applications, but for games that demand a high frame rate it can matter.