You may use fixed time physics step to change simulation speed.
I prefer to use semi-fixed time step with physics, so simulation will look and feel pretty much same on all devices.
Code could be improved with smoothing by predicating next position/angle, but I haven't found it necessary yet
See: http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d
Here's slightly modified code with semi-fixed time step physics:
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
SetRandomSeed( 10 )
SetVirtualResolution ( 480, 320 )
global fixedTimestepAccumulator# = 0
global targetFPS# = 60.0
global physTimeStep# = 0
global singlePhysStep# = 0.06
// Play with physTimeStep# and singlePhysStep# values to change physics simulation speed
physTimeStep# = 1.0 / targetFPS#
// Normal "slow" physics speed
// singlePhysStep# = physTimeStep#
// Set desired FPS
SetSyncRate(targetFPS#, 0)
// Simulate device only capable at 30 fps
// SetSyncRate(30, 0)
// load an image
LoadImage ( 1, "small_ball.png" )
LoadImage (2, "bar.jpg")
// create 5 sprites
CreateSprite ( 1, 1 )
CreateSprite ( 2, 1 )
CreateSprite ( 3, 1 )
CreateSprite ( 4, 1 )
CreateSprite ( 5, 1 )
CreateSprite ( 6,2 )
SetSpritePosition (6,100,10)
// position in a row
SetSpritePosition ( 1, 120, 180 )
SetSpritePosition ( 2, 180, 180 )
SetSpritePosition ( 3, 240, 180 )
SetSpritePosition ( 4, 300,180 )
SetSpritePosition ( 5, 360, 180 )
// set their shapes
SetSpriteShape ( 1, 1 )
SetSpriteShape ( 2, 1 )
SetSpriteShape ( 3, 1 )
SetSpriteShape ( 4, 1 )
SetSpriteShape ( 5, 1 )
// turn physics on
SetSpritePhysicsOn ( 1, 2 )
SetSpritePhysicsOn ( 2, 2 )
SetSpritePhysicsOn ( 3, 2 )
SetSpritePhysicsOn ( 4, 2 )
SetSpritePhysicsOn ( 5, 2 )
SetSpritePhysicsOn (6,1)
SetSpritePhysicsRestitution ( 1, 0.6 )
SetSpritePhysicsRestitution ( 2, 0.6 )
SetSpritePhysicsRestitution ( 3, 0.6 )
SetSpritePhysicsRestitution ( 4, 0.6 )
SetSpritePhysicsRestitution ( 5, 0.6 )
CreateRevoluteJoint( 1, 1, 6, 136, 20, 0 )
CreateRevoluteJoint( 2, 2, 6, 196, 20, 0 )
CreateRevoluteJoint( 3, 3, 6, 256, 20, 0 )
CreateRevoluteJoint( 4, 4, 6, 316, 20, 0 )
CreateRevoluteJoint( 5, 5, 6, 376, 20, 0 )
SetPhysicsDebugOn ( )
lastFrame# = Timer ( )
do
if ( GetPointerstate ( ) = 1 )
x# = GetPointerX ( )
y# = GetPointerY ( )
gsh = getspritehit(x#,y#)
gje = getjointexists (6)
if ((gsh>0) and (gje=0))
CreateMouseJoint (6,gsh,x#,y#,50000)
print ("Made a mouse joint")
endif
if (gje)
SetJointMouseTarget( 6, x#, y# )
print ("Targetted a mouse joint")
endif
else
if (getjointexists(6))
print ("Deleted a joint")
DeleteJoint (6)
ENDIF
ENDIF
// Update timer
thisFrame# = Timer ( )
difference# = thisFrame# - lastFrame#
lastFrame# = thisFrame#
// Update physics
UpdatePhysics(difference#)
Sync()
loop
// Based on Fixed time-step implementation in Box2D
// http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d
function UpdatePhysics ( dt# )
#constant MAXPHYSSTEPS 5
fixedTimestepAccumulator# = fixedTimestepAccumulator# + dt#;
nSteps = Floor(fixedTimestepAccumulator# / physTimeStep#)
// To avoid rounding errors, touches fixedTimestepAccumulator# only if needed.
if nSteps > 0
fixedTimestepAccumulator# = fixedTimestepAccumulator# - (nSteps * physTimeStep#)
endif
stepsClamped = nSteps
if stepsClamped > MAXPHYSSTEPS then stepsClamped = MAXPHYSSTEPS
for i = 1 to stepsClamped
StepPhysics(singlePhysStep#)
next i
endfunction