Games ProtoType PlanetsGravity

Gunther

Active Member
Licensed User
Longtime User
This is what I am working on as prototype.

Not that much to see, but funny to see the possible tracks on different locations. You can drag the planets on a new locations, too.

upload_2018-12-12_12-21-47.png
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Thanks, noted for the further items! :)
 

Gunther

Active Member
Licensed User
Longtime User
Do the planets have different gravity values?
Yes, according to the radius they have different "gravity" values. Since kinematic bodies don't have a mass one need to work around that.

You can put them in the center together then at a certain distance there is an almost stable orbit. Anyhow after 120 secs the astronaut will be killed, to avoid filling the screen with astronauts. And he has only 15 secs after a planet is touched.

upload_2018-12-12_12-54-6.png


The niceset tracks one will get if you put the small planet to one corner (= almost no influemce) and then play with two planets.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Nicely done.

I got frustrated that I couldn't get a stable orbit around a single planet though
Yes I tried that as well.
 

Gunther

Active Member
Licensed User
Longtime User
Tip: change the stars angle interval to 1.

Unfortunately I am getting a NullPointerException after certain time. Not the exact time everytime but plusminus 2 secs it occurs. The number (-86) is the Bodyangle in degree.

It happens after the internal GraphicCache change. The PNG has a size of about 75kb.

B4X:
 -86
 -86
 -86
 -86
 -86
 -86
 -86
 -86
 -86
 -87
 -87
 -87
 -87
 -87
 -87
 -87
 -87
 -87
Trim Cache
Before: 31482924
After: 7529704
java.lang.RuntimeException: java.lang.NullPointerException
    at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1020)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at b4j.example.bitmapcreator._drawrotatedcbc(bitmapcreator.java:2490)
    at b4j.example.x2spritegraphiccache._getgraphic2(x2spritegraphiccache.java:544)
    at b4j.example.x2spritegraphiccache._getgraphic2(x2spritegraphiccache.java:515)
    at b4j.example.x2spritegraphiccache._getdrawtask(x2spritegraphiccache.java:404)
    at b4j.example.x2bodywrapper._createdrawtaskbasedoncache(x2bodywrapper.java:119)
    at b4j.example.x2bodywrapper._updategraphic(x2bodywrapper.java:251)
    at b4j.example.x2bodywrapper._tick(x2bodywrapper.java:237)
    at b4j.example.x2utils$ResumableSub_MainLoop.resume(x2utils.java:922)
    at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1018)
    ... 7 more
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Can you upload the project?

Here it is.

In this case the crash comes around -152°.

It looks like the BC cache is erased more than expected (not all 360x graphics are available anymore). Or a limit is reached.

If you change the "zoom":
B4X:
X2.ConfigureDimensions( X2.CreateVec2( WorldWidth / 2, WorldHeight / 2 ), WorldWidth * .9 )

It craches earlier - with .9 => -124°

With 1.5 - no crash.
 

Attachments

  • GravityNPException.zip
    105.2 KB · Views: 311
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is indeed a bug. It is related to a previous change in the way that rotated graphics are created. You can fix it with this code in TrimCache:

B4X:
For Each m As Map In data.MapsOfCompressedBCs
           Dim zero As CompressedBC = m.Get(0) '<--- new
           m.Clear
           m.Put(0, zero) '<--- new
       Next

It is fixed for the next update.

As a general rule it is not good that the cache needs to be cleared too frequently. It can have a bad impact on the performance.

You have two options:
1. Increase the cache size: MAX_SIZE_OF_ALL_COMPRESSEDBCS

2. Set the angle interval to 2 or 3.
 

Gunther

Active Member
Licensed User
Longtime User
For the ProtoType I choosed angle to 2 ;o)

The TestProject runs fine with adding this suggested two lines in the X2SpriteGraphicCache.bas (Line 240 ff)

Thanks.
 
Last edited:
Top