You need to apply a force to your lasers that is exactly opposite to the effects of the constant acceleration applied by the engine's gravity.
From the help:
Quote: "Gravity is a constant acceleration applied to all physics objects equally, regardless of mass. Whereas a force applies an acceleration proportional to the objects mass. To counteract gravity with a force will require accounting for mass. "
A test:
// Project: gravtest
// Created: 2015-02-25
// set window properties
SetWindowTitle( "gravtest" )
SetWindowSize( 1024, 768, 0 )
// set display properties
`SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
CreateImageColor(1,255,0,255,255)
createsprite(1,1)
setspritesize(1,5,5)
setspriteposition(1,10,10)
SetSpritePhysicsFriction (1, 0)
SetSpritePhysicsOn (1, 2)
SetSpritePhysicsMass (1, 0)
SetPhysicsGravity(0,50)
` to stop the laser slowing down when bouncing
SetSpritePhysicsRestitution (1,1)
`Settle box2d down a little:
sync()
sync()
` To get the laser moving
SetSpritePhysicsForce (1, GetSpriteXByOffset(1), GetSpriteYByOffset(1), 10000, 0)
`Bounce the laser across the screen!
do
` to counter Gravity
SetSpritePhysicsForce( 1,GetSpriteXByOffset(1),GetSpriteYByOffset(1),0,-50)
Print( ScreenFPS() )
Sync()
loop