1
votes

I'm developing a game on iOS Sprite Kit and on AndEngine (with Box2d) simultaneously. I want the game's physics to be identical on both platforms. Sprite Kit uses Box2d internally for physics simulation same as in AndEngine.

In AndEngine's Box2d, I use body.SetLinearVelocity(x,y) where x = y = density/34f(some constant value)

In Sprite Kit, I use ball.physicsBody.velocity = CGVectorMake(x,y)

I similarly use the code below for gravity & impulse in AndEngine & Sprite Kit respectively.

For Gravity :

In AndEngine's Box2d, I use

mPhysicsWorld = new FixedStepPhysicsWorld(60, 1, new Vector2(0, -1f),false, 6, 2);

In Sprite Kit, I use

self.physicsWorld.gravity = CGVectorMake(0, -1);

For Impulse :

In AndEngine's Box2d, I use

body.applyLinearImpulse(new Vector2(2f, 2f),new Vector2(body.getWorldCenter().x, body.getWorldCenter().y));

In Sprite Kit, I use

[ball.physicsBody applyImpulse:CGVectorMake(2,2)];

In AndEngine I give the velocity is given w.r.t the density of the devices so that we can make the gameplay looks same in all android devices like the ball starts and ends at almost the same time in all devices(Mobiles, Tablets)

I want to know what value to be given in sprite kit w.r.t AndEngine so that physics in both platforms looks similar. Also whether we have to give different velocity for different screen sizes like in AndEngine or same velocity should be given for all iOS devices.

Apart from setting velocity, I need to know whether I should keep the Gravity, Impulse variable according to screen sizes.

1
I agree with Steffen. Since SpriteKit is closed source, you cannot even know how they have modified Box2D, let alone change it yourself. Even AndEngine is a port of Box2D to a different language, which will often introduce some differences. If you really want to have standardization across platforms, I would suggest using something like cocos2d-x where you can use the exact same source code for both iOS and Android. - iforce2d

1 Answers

1
votes

Identical physics between two different game engines, two different versions of Box2D (with unknown modifications made to the Sprite Kit version), two different device platforms, two different programming languages, and perhaps even two different sets of hardware (iOS vs Android)? That is next to impossible.

You would have to run the exact same version of Box2D in both Sprite Kit and AndEngine for a start. Since you can't know the internal modifications made to Box2D by the SK developers. And there are some.

Then you need to ensure the code is compiled with the same build settings, specifically as it pertains to floating point operations.