Here's a little example I just whipped up (using impulse
):
// Project: boxjump
// Created: 2015-06-17
// Author: Conrad Brown - UzmaDesign
// set window properties
SetWindowTitle( "boxjump" )
// set display properties
SetOrientationAllowed( 0, 0, 1, 1 )
CreateImageColor(1,255,255,255,255)
` Create boxy landscape
ground = createsprite(1)
setspritesize(ground,1000,10)
setspriteposition(ground,0,90)
setspritephysicson(ground,1)
for t=1 to 100
createsprite(t,1)
height = random(15,50)
setspritesize(t,5,height)
SetSpriteColor(t,random(150,255),random(150,255),random(150,255),255)
SetSpritePosition(t,random(40,950),90-height)
setspritephysicson(t,1)
next t
` Create player
player = createsprite(1)
SetSpritePositionByOffset(player,30,40)
SetSpritePhysicsRestitution(player,0.9)
setspritephysicson(player,2)
` Control left/right movement
AddVirtualJoystick(1,20,80,20)
SetVirtualJoystickDeadZone(0.03)
` jump button
AddVirtualButton(1,20,20,20)
SetVirtualButtonPosition(1,80,80)
SetVirtualButtonActive(1,1)
do
SetSpritePhysicsImpulse( player, GetSpriteXByOffset(player), GetSpriteYByOffset(player), GetVirtualJoystickX(1)/30.0, 0 )
if GetVirtualButtonPressed(1)
SetSpritePhysicsVelocity(player,GetSpritePhysicsVelocityX(player),0)
SetSpritePhysicsImpulse(player, GetSpriteXByOffset(player),GetSpriteYByOffset(player), 0, -2)
endif
Print( ScreenFPS() )
Sync()
setviewoffset(GetSpriteXByOffset(player)-30,0)
if GetRawKeyState(27)
end
endif
loop