Just a quick question that I haven't been able to find an answer to, I am creating an engine for a game, I have begin making the engine in C++ but I want to make the game in java. My question is, is there a way to maker my game in a different language on a separate "layer"?


Yes, this kind of inter-operation between languages is doable and in fact fairly common. For games, it's typically done as part of implementing a scripting system, which may give some hints as to where to look for further research.

The specific process depending on which languages you'd like to pair together. Almost all languages you're likely to use have some kind of inter-operability mechanism, most of them based on the standardized ABI of C.

For Java in particular, you'd want to look at the JNI (or possibly other community projects like JNA). The JNI will allow you to call functions implemented in C from your Java code, so could implement your "engine functionality" in native code but have your game logic written in Java.

One way to go about this is to declare the existence of the native methods in Java using the native keyword, generate a boilerplate header using the -h flag of the Java compiler, implement the native functions in that header in C++, compile the result into a shared library, load that library from Java and call the functions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.