Simulating an Edge Shape in Android
Tinniam V Ganesh 270004Y158 Visits (2179)
Here is a small post on how I managed to simulate an Edge Shape in Android. I wanted to do this after I saw the Java demo of Box2D in JBox
Since it is a cosine curve I place a ball shape for every point on a cosine function, close to each other to seem continuous and create a body from the Sprite with physical properties.
for (int i = 0; i < nBodies; ++i)
float angle = (float) ((10.0 * PI * i)/180.0);
float y1 = 300 + (flo
circles[i] = new Sprite(x1, y1,
circlesBody[i] = Phys
x1 = (float) (x1 + 0.5);
So this can be done for every mathematical curve. I also intended to create other curves like the Archimedes Spiral and the Lemniscate. Maybe I will leave that for a rainy day!! :-)
However, I am not sure how to create a irregular edge shape. I will probably figure that out.
The egde shape is made to be a STATIC_BODY. I then took code of creating Animated Sprites at the point where I touch from AndEngine examples (Phy
body = Phys
The effect is better if the phone is horizontal to the ground and not so great if the phone is kept vertical and the bodies do not seem to shoot off.
The simulation can be seen at Simulating an Edge Shape
You can clone the entire project from Github at EdgeShape.