I've been talking about this problem for a few days on discord, and blinkOk recommended me to make a thread about it
I have some problems with box2d physics
Moving the window or click on the title bar causes non-sleeping sprites to behave strangely
like here for example, where the sprite gains negative velocity and starts to jump.
https://streamable.com/czy5xi
SetWindowTitle("Physics Test")
SetVirtualResolution(320, 180)
SetWindowSize(1280, 720, 0)
SetClearColor(151, 170, 204)
UseNewDefaultFonts(1)
SetPhysicsScale(0.2)
SetPhysicsGravity(0, 276)
SetSyncRate(0, 1)
spr = CreateSprite(0)
SetSpriteSize(spr, 25, 25)
SetSpritePositionByOffset(spr, GetVirtualWidth()/2, GetVirtualHeight()/2)
SetSpritePhysicsOn(spr, 2)
SetPhysicsSleeping(0)
do
Print(ScreenFPS())
Print(GetFrameTime())
Sync()
loop
and notice that the framerate goes down when you move the window, this could be the cause of the problem
Here is another example where the ball loses speed when the window is moved
https://streamable.com/2nlbjs
SetPrintSize( 40 )
SetVirtualResolution ( 320, 480 )
CreateSprite ( LoadImage ( "background3.jpg" ) )
LoadImage ( 1, "small_ball.png" )
CreateSprite ( 1, 1 )
SetSpritePosition ( 1, 0, 0 )
SetSpritePhysicsOn ( 1, 2 )
do
Print(GetSpritePhysicsVelocityY(1))
Sync()
loop
happens only in sprites that are not sleeping
I found a temporary solution to this, changing the update() to as fixed value, but this causes problems especially if the hardware running the game is unable to maintain 60fps
#CONSTANT FIXED_FRAME_TIME 0.016667
Update(FIXED_FRAME_TIME)
render()
swap()
as seen here the sprite doesn't jump, and the problem is solved, but this has its bad parts, if the game is running at 30fps
https://streamable.com/bj081v
#CONSTANT FIXED_FRAME_TIME 0.016667
SetWindowTitle("Physics Test")
SetVirtualResolution(320, 180)
SetWindowSize(640, 360, 0)
SetClearColor(151, 170, 204)
UseNewDefaultFonts(1)
SetPhysicsScale(0.2)
SetPhysicsGravity(0, 276)
SetSyncRate(0, 0)
spr = CreateSprite(0)
SetSpriteSize(spr, 25, 25)
SetSpritePositionByOffset(spr, GetVirtualWidth()/2, GetVirtualHeight()/2)
SetSpritePhysicsOn(spr, 2)
SetPhysicsSleeping(0)
SetSyncRate(60, 1)
SetPrintSize(25)
fixed = 1
do
print(ScreenFPS())
print("Spr VY: " + str(GetSpritePhysicsVelocityY(spr)))
if fixed = 1
Update(FIXED_FRAME_TIME)
else
Update(0)
endif
render()
swap()
loop
the cause of this may be because the game loses framerate when the top bar is clicked or moved as MadBit said here
https://forum.thegamecreators.com/thread/219478?page=3#msg2662817