I have been experimenting a bit and found that if I measure the time in a _GL sub (normally for open GL rendering) it seem to work the way I want it to. It's a hack-ish way of doing it and i dont know why it works, if the timer get the time from the GPU instead just because its inside the _GL sub or if the measured time just happened to be at the right place... someone might know..
I found this because I was going to try to learn how to render with open GL instead of just using putimage like Ive done so far. I have noticed that programs that use open GL seem very smooth. The one where they simulate the pandemic in particular:
https://www.qb64.org/forum/index.php?topic=2827.0The green dots simulating people moves super smooth in the open GL version that can be found some posts down the page. If you change the size of them to larger ones its really noticable.
Anyway, below is the new code I made. Since i am new to this I dont really understand why it works better, it may just be better placement of the timers and have completely nothing to do with the _GL sub per see. By the way, the 320x240 res screen is just from me experimenting as well. If I manage to make a game I will try to adjust it so i have like a native low resolution for the game and then scale it to whatever the player has as desktop. But thats for later.
Do anyone else see a difference in movement?
CONST ScreenEndRight
= 320 '1920 CONST ScreenEndBottom
= 240 '1080 CONST ScreenWidth
= 320 '1920 CONST ScreenHeight
= 240 '1080 CONST ScreenCenterX
= (ScreenWidth
/ 2) CONST ScreenCenterY
= (ScreenHeight
/ 2)
'Shot sprite
'8x8px
'(Part of code is borrowed from somewhere like a tutorial or something...).
ShotSpriteData:
DATA &HFFFC00FC,&HFFFC00FC,&HFF000000,&HFF000000,&HFF000000,&HFF000000,&HFFFC00FC,&HFFFC00FC DATA &HFFFC00FC,&HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFF000000,&HFFFC00FC DATA &HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFFF7D8A5,&HFF000000 DATA &HFFFC00FC,&HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFF000000,&HFFFC00FC DATA &HFFFC00FC,&HFFFC00FC,&HFF000000,&HFF000000,&HFF000000,&HFF000000,&HFFFC00FC,&HFFFC00FC
'Set some properties of the shot
Shots(0).x! = 0
Shots(0).y! = 100
Shots(0).spritewidth% = 8
Shots(0).spriteheight% = 8
Shots(0).dir%% = 0
Shots(0).sprite% = shotsprite%
AllowGL%% = -1
Shots(0).x! = (Shots(0).x! + 2)
IF Shots
(0).x!
>= (ScreenEndRight
+ Shots
(0).spritewidth%
) THEN Shots
(0).x!
= (ScreenEndLeft
- Shots
(0).spritewidth%
)
endtime_gltest#
= TIMER(0.001) starttime_gltest#
= TIMER(0.001)
delta_gltest# = (endtime_gltest# - starttime_gltest#)
IF delta_gltest#
<= (1 / 60) THEN
delta_gltest#
= (TIMER(0.001) - starttime_gltest#
) PRINT (delta_gltest#
* 1000)
' _GLEND
' _GLFLUSH