Hi.
I made a game in Classic long time ago in 2018 and I figured I port the game over to Studio and this time use the level editor, just for fun.
the game involve sprites moving on the screen and as I was porting over the game to Studio, I have noticed the moving sprites are moving faster each time I switch back and forth between the scenes.
When I debug it, the numbers like speed, position, frame rate, time are correct yet the sprites are moving noticeable faster each time a change the scene and can not figure out what the problem is.
After waiting some time, the sprites slow back down to normal (real) speed on their own.
I don't have this problem in the old 2018 version of AppGameKit Classic, but I do experience this problem in the current version of Studio and Classic with both OpenGL and Vulkan renderers and on all platform, Windows, Android, Web, macOS, iOS.
I am uncertain if it a bug or an error in my code.
I have attached a sample project reproducing the problem.
For those who don't want to download the project, here is the code:
#renderer "Advanced" //same result with both renderers.
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "speed-test" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
SetVSync(1) //same result with any vsync mode
//includes
#include "scene1.scene"
//globals
global currentScene as string = "scene1"
global switch as integer = 0
//load scene1
scene1_setup()
global candies as integer[]
createCandy() //just create one candy at the start
do
Print( ScreenFPS() )
updateCore()
if currentScene = "scene1" then updateScene1()
if currentScene = "scene2" then updateScene2()
Sync()
loop
function updateScene1()
if(Timer() > 1)
createCandy()
ResetTimer()
endif
moveCandies(200)
if GetPointerReleased() and switch = 0
scene1_cleanup()
DeleteAllSprites()
for i = 0 to candies.length
candies.remove()
next i
scene2_setup()
currentScene = "scene2"
switch = 1
ResetTimer()
endif
endfunction
function updateScene2()
if GetPointerReleased() and switch = 0
scene2_cleanup()
scene1_setup()
currentScene = "scene1"
switch = 1
endif
If GetTextExists(scene2_timertext) then SetTextString(scene2_timertext, Str(Timer()))
endfunction
function updateCore()
//to avoid switching between the scenes immediately, we toggle a switch and we set it back to 0 when the mouse down
if GetPointerPressed() then switch = 0
endfunction
function createCandy()
spr = CloneSprite(scene1_candy_sprite)
SetSpritePosition(spr,1100,400)
candies.insert(spr)
endfunction
function moveCandies(_speed as integer)
_speed = _speed * GetFrameTime()
for i = 0 to candies.length
if GetSpriteExists(candies[i])
spr = candies[i]
x = GetSpriteX(spr)
SetSpriteX(spr, x - _speed)
endif
next i
endfunction
Any idea what is causing this weird behaviour?
Thanks.