Page 2 of 2

Re: Output to Java or ObjC / C++

Posted: Mon Apr 29, 2013 12:51 am
by iforce2d
Exporting to C++ and translating to Java is probably the least efficient and flexible method possible for doing this, and you are losing out on convenient ways to find named items, custom properties, and quick turnaround time to test your scenes. It almost entirely defeats the purpose of having an editor at all, and all of that for only hours and hours more work. In fact, it might even be quicker to just click on items in RUBE and copy the values from the properties panel into your source code :)

If you want straight jBox2D, there is an example of that on the 'Supported loaders' page I linked to, and the instructions are on the b2dJson page I linked to above. It seems like you are dreading that using the loader is a real chore or something, but here is an example for straight jBox2D:

Code: Select all

Jb2dJson json = new Jb2dJson();
StringBuilder errorMsg = new StringBuilder();
World world = json.readFromFile("car.json", errorMsg);
Of course, you need to have the right classes available in your project to do this, but you only need to set that up once, and it's orders of magnitude less work than the way you're doing it now. The way you are "learning the framework" is like learning to drive a car by learning to cast steel into an engine block.

Re: Output to Java or ObjC / C++

Posted: Mon Apr 29, 2013 1:17 pm
by Eddy8555
And actually the main reason is probably that I'd like to write game logic that can't be done with RUBE, so I have to have the source code to do it.

Re: Output to Java or ObjC / C++

Posted: Mon Apr 29, 2013 2:35 pm
by Eddy8555
I set up the Jb2dJson loader and run it successfully over the sample scenes. But still, to use it in Android I'd probably need to customize it, and in any case I'd have to have the source code to add game logic.

For example our game is planned to be multiplayer, and so I'll need to collect data on the bodies and have it communicate with the server. How would I do that without source code?

Re: Output to Java or ObjC / C++

Posted: Mon Apr 29, 2013 5:48 pm
by iforce2d
Assuming you mean how would you find a particular body, joint etc after loading the scene, please take a look at this page, at the section about "Retrieving objects of interest": http://www.iforce2d.net/b2djson/#naming

The samples for the Jb2dJson loader you were using should have examples of loading vehicle scenes and then controlling the wheel joints to drive them.

Yes, to use it in Android you will probably have to adapt it a bit - I have not used Android myself yet to help much with that unfortunately.

Re: Output to Java or ObjC / C++

Posted: Tue Apr 30, 2013 6:09 am
by Eddy8555
The approach of getting the bodies (and other box2d objects) from the JSON -- or I guess from the world.getBodyList is great. I could write an init method to make sure the measurement units fit the screen, and implement all my other game logic.

But for the Jb2dJson to work for Android it would probably have to go through some changes. When trying to run it I'm getting a bunch of errors, that from previous experience I think indicate that the jbox2d-rube-with-dependencies jar has classes that Java implements through native code -- possibly classes from the awt package -- possibly image manipulation classes -- and Android can't handle those.

This is a typical warning: "Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.log4j.chainsaw.Main$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly

After a bunch of these the final verdict from the Android launcher:

[2013-04-30 09:00:47 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/jbox2d/callbacks/ContactFilter;
[2013-04-30 09:00:47] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/jbox2d/callbacks/ContactFilter;

Re: Output to Java or ObjC / C++

Posted: Tue Apr 30, 2013 11:30 am
by iforce2d
Seems like the logging class JBox2D uses by default is not available? I guess you could cut the logging right out, or check what everyone else is doing. Like I say I know nothing about Android, but these links might help:

http://stackoverflow.com/questions/2915 ... in-android
http://mindpipe.blogspot.jp/2011/11/and ... rties.html
http://adevedo.com/content/using-log4j- ... plications

Re: Output to Java or ObjC / C++

Posted: Wed Jun 05, 2019 11:33 am
by Rakesh579
Those links are quite understandingly great.