Hi again. First time messing with Physics, so here goes. My code:
SetWindowSize( sW, sH, 0 )
// set display properties
//SetVirtualResolution( GetDeviceWidth() , GetDeviceHeight() )
SetVirtualResolution( sW , sH )
SetOrientationAllowed( 0, 0, 1, 1)
Global sW = 1366
Global sH = 768
#include "Functions.agc"
Global BplaneSpr
Global x# as integer
Global levelSpr
levelImg = loadimage("level.png")
levelSpr = createsprite(levelImg)
SetSpritePosition(levelSpr,sW,0)
setspritesize(levelSpr,sW,sH)
BplaneImg = LoadImage("planes/planeBlue1.png")
BplaneSpr = createsprite(BplaneImg)
SetSpritePosition(BplaneSpr,sW/2,sH -GetSpriteHeight(BplaneSpr))
SetSpriteOffset(BplaneSpr, getspritex(BplaneSpr /2), getspritey(BplaneSpr /2))
SetSpritePhysicsOn(BplaneSpr, 2)
do
setviewoffset(0,0)
physicsVelocity()
debug()
Sync()
loop
function debug()
print(getspritex(BplaneSpr))
print(getspritey(BplaneSpr))
endfunction
my Function code:
function physicsVelocity()
SetPhysicsWallBottom(1) //These don't seem to do anything, but i've added them just incase.
SetPhysicsWallLeft(1)
SetPhysicsWallRight(1)
SetPhysicsWallTop(1)
SetSpritePhysicsCanRotate(BplaneSpr,0) // 0 can't, 1 can rotate.
// The number is the bounce potential - 0 = low, 1 = lots of bounce
SetSpritePhysicsRestitution(BplaneSpr,0.5)
do
if getpointerpressed()=1 and getspritehittest(BplaneSpr,screentoworldx(getpointerx()),screentoworldy(getpointery()))
setSpritePhysicsVelocity( BplaneSpr, 0, -getpointery() )
else
//SetPhysicsGravity ( 0, 10 ) // gravity pull on the X axis, and the Y axis
SetPhysicsGravity(0,400)
endif
sync()
loop
endfunction
Ok, now this works as expected. But if i setviewoffset(sW,0) and then set the plane's position to that off:
SetSpritePosition(BplaneSpr,sW+ sW/2,sH -GetSpriteHeight(BplaneSpr))
The plane just falls through the floor.... Why's that?
Thanks
EDIT: The bounce is stronger if i click the plane at the bottom of the screen, than if i'd click the plane at the top. Anyway this can be equal regardless of position clicked?
Khadin