Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For everyone who makes games !
#1
I would like to bring it to the attention of those who make games. Even with a 2D game, it's worth considering what you want to show. The image update. Until now I never dealt with it, I always used a value. A value that is good for the speed of my current computer. In my last game, I was shocked at how important this is to the perfection of the display.

It also means a lot if someone makes a 2D game!

Something moves on the screen. This will have a path, a process. How many parts this process is divided into and how many times it is mapped determines the quality of the animation.

It is worth taking this into account before making the game! It can also be built in afterwards.

Delta timing
https://en.wikipedia.org/wiki/Delta_timing

I created an example program to show in which cases it is necessary to multiply with 'deltatime' or to use it as a power exponent.

In the main cycle, the value of _LIMIT can be changed so that the animation speed is constant.

If you are making a game, I recommend that you include it so that the program can be set to any image update later.

Code: (Select All)
monx = 600
mony = 600
mon = _NewImage(monx, mony, 32)
Screen mon

'placing balls horizontally
red_ballx = 200
blue_ballx = 400
green_ballx = 300

blue_bally = 1
ballr = 20 'balls radius


gravity = .2



fps = 30
Color _RGB32(150, 150, 150)
Do: _Limit fps

    fps = fps - (_KeyDown(Asc("+")) - _KeyDown(Asc("-"))) * .5
    If fps < 5 Then fps = 5
    If fps > 500 Then fps = 500

    deltatime = 30 / fps


    Cls: Color _RGB32(100, 100, 100)
    Locate 1, 1: Print "+/- FPS setting              SPACE-green ball jump"
    Locate 3, 1: Print "FPS, (_LIMIT value)"; Int(fps), "deltatime:"; deltatime




    legalso_ypozicio = mony - ballr 'this value is the lowest position given by the size of the window and the ball, when the balls are on the ground


    'RED BALL -------------------------------------------------------------------------------------------------------------------------------------
    red_yvec = red_yvec + gravity * deltatime
    red_bally = red_bally + red_yvec * deltatime
    If legalso_ypozicio < red_bally Then red_bally = legalso_ypozicio: red_yvec = -14 'can also be used for jumping, yvec, momentum vector, which gravity tries to pull down in every cycle
    Color _RGB32(255, 20, 20)
    Circle (red_ballx, red_bally), ballr
    Paint (red_ballx, red_bally)


    'GREEN BALL  ------------------------------- same as the red ball, only you jump with SPACE
    green_yvec = green_yvec + gravity * deltatime
    green_bally = green_bally + green_yvec * deltatime
    If legalso_ypozicio < green_bally Then
        green_bally = legalso_ypozicio
        If _KeyDown(Asc(" ")) Then green_yvec = -5 'you jump to SPACE, which you can only do when you are on the ground (you can't jump while falling). it also has the power of jumping
    End If
    Color _RGB32(20, 255, 20)
    Circle (green_ballx, green_bally), ballr
    Paint (green_ballx, green_bally)



    'BLUE BALL
    blue_bally = blue_bally * 1.12 ^ deltatime '<------------------   in such cases deltatime must be increased!
    If legalso_ypozicio < blue_bally Then blue_bally = 1
    Color _RGB32(20, 20, 255)
    Circle (blue_ballx, blue_bally), ballr
    Paint (blue_ballx, blue_bally)


    _Display
Loop
Reply
#2
(12-08-2023, 11:02 PM)MasterGy Wrote: I would like to bring it to the attention of those who make games. Even with a 2D game, it's worth considering what you want to show. The image update. Until now I never dealt with it, I always used a value. A value that is good for the speed of my current computer. In my last game, I was shocked at how important this is to the perfection of the display.

It also means a lot if someone makes a 2D game!

Something moves on the screen. This will have a path, a process. How many parts this process is divided into and how many times it is mapped determines the quality of the animation.

It is worth taking this into account before making the game! It can also be built in afterwards.

Delta timing
https://en.wikipedia.org/wiki/Delta_timing

I created an example program to show in which cases it is necessary to multiply with 'deltatime' or to use it as a power exponent.

In the main cycle, the value of _LIMIT can be changed so that the animation speed is constant.

If you are making a game, I recommend that you include it so that the program can be set to any image update later.

Code: (Select All)
monx = 600
mony = 600
mon = _NewImage(monx, mony, 32)
Screen mon

'placing balls horizontally
red_ballx = 200
blue_ballx = 400
green_ballx = 300

blue_bally = 1
ballr = 20 'balls radius


gravity = .2



fps = 30
Color _RGB32(150, 150, 150)
Do: _Limit fps

    fps = fps - (_KeyDown(Asc("+")) - _KeyDown(Asc("-"))) * .5
    If fps < 5 Then fps = 5
    If fps > 500 Then fps = 500

    deltatime = 30 / fps


    Cls: Color _RGB32(100, 100, 100)
    Locate 1, 1: Print "+/- FPS setting              SPACE-green ball jump"
    Locate 3, 1: Print "FPS, (_LIMIT value)"; Int(fps), "deltatime:"; deltatime




    legalso_ypozicio = mony - ballr 'this value is the lowest position given by the size of the window and the ball, when the balls are on the ground


    'RED BALL -------------------------------------------------------------------------------------------------------------------------------------
    red_yvec = red_yvec + gravity * deltatime
    red_bally = red_bally + red_yvec * deltatime
    If legalso_ypozicio < red_bally Then red_bally = legalso_ypozicio: red_yvec = -14 'can also be used for jumping, yvec, momentum vector, which gravity tries to pull down in every cycle
    Color _RGB32(255, 20, 20)
    Circle (red_ballx, red_bally), ballr
    Paint (red_ballx, red_bally)


    'GREEN BALL  ------------------------------- same as the red ball, only you jump with SPACE
    green_yvec = green_yvec + gravity * deltatime
    green_bally = green_bally + green_yvec * deltatime
    If legalso_ypozicio < green_bally Then
        green_bally = legalso_ypozicio
        If _KeyDown(Asc(" ")) Then green_yvec = -5 'you jump to SPACE, which you can only do when you are on the ground (you can't jump while falling). it also has the power of jumping
    End If
    Color _RGB32(20, 255, 20)
    Circle (green_ballx, green_bally), ballr
    Paint (green_ballx, green_bally)



    'BLUE BALL
    blue_bally = blue_bally * 1.12 ^ deltatime '<------------------   in such cases deltatime must be increased!
    If legalso_ypozicio < blue_bally Then blue_bally = 1
    Color _RGB32(20, 20, 255)
    Circle (blue_ballx, blue_bally), ballr
    Paint (blue_ballx, blue_bally)


    _Display
Loop
This is very cool. I've already needed this a few times, but didn't know how to implement it... Thanks, MasterGy!
Reply
#3
(12-08-2023, 11:02 PM)MasterGy Wrote: I would like to bring it to the attention of those who make games. Even with a 2D game, it's worth considering what you want to show. The image update. Until now I never dealt with it, I always used a value. A value that is good for the speed of my current computer. In my last game, I was shocked at how important this is to the perfection of the display.

It also means a lot if someone makes a 2D game!

Something moves on the screen. This will have a path, a process. How many parts this process is divided into and how many times it is mapped determines the quality of the animation.

It is worth taking this into account before making the game! It can also be built in afterwards.

Delta timing
https://en.wikipedia.org/wiki/Delta_timing

This is a fantastic example of how to use delta time and we should put in wiki @RhoSigma - and @TerryRitchie if you don't have a tutorial on this you should!

Thanks @MasterGy!
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#4
(12-09-2023, 02:21 AM)grymmjack Wrote: This is a fantastic example of how to use delta time and we should put in wiki @RhoSigma - and @TerryRitchie if you don't have a tutorial on this you should!

Thanks @MasterGy!
Yep, timing methods is something that I have on the list of future additions. Thanks to @MasterGy I now have an excellent example of how to implement Delta time.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#5
When reading that Wiki page correctly, then its almost the same thing I do here:

Measuring time myself in that way is what I do to keep approx. 25FPS, you find those kind of constructs a lot in my GuiTools Framework eg. to avoid flicker when moving slider/scroller knobs etc..

Code: (Select All)
_DISPLAY 'stop _AUTODISPLAY

stim# = TIMER(0.001) 'get start time
DO
    '---------------------
    'do drawing stuff here
    '---------------------
    etim# = TIMER(0.001) - stim# 'time needed for drawing (delta time)
    IF etim# < 0 THEN etim# = etim# + 86400 'midnight fix
    IF etim# >= 0.04 THEN 'desired FPS 1/25 = 0.04
        _DISPLAY
        stim# = TIMER(0.001) 'restart timer
    END IF
LOOP UNTIL done%

_AUTODISPLAY 'back to normal
Reply
#6
(12-09-2023, 09:26 AM)RhoSigma Wrote: When reading that Wiki page correctly, then its almost the same thing I do here:

Measuring time myself in that way is what I do to keep approx. 25FPS, you find those kind of constructs a lot in my GuiTools Framework eg. to avoid flicker when moving slider/scroller knobs etc..

Code: (Select All)
_DISPLAY 'stop _AUTODISPLAY

stim# = TIMER(0.001) 'get start time
DO
    '---------------------
    'do drawing stuff here
    '---------------------
    etim# = TIMER(0.001) - stim# 'time needed for drawing (delta time)
    IF etim# < 0 THEN etim# = etim# + 86400 'midnight fix
    IF etim# >= 0.04 THEN 'desired FPS 1/25 = 0.04
        _DISPLAY
        stim# = TIMER(0.001) 'restart timer
    END IF
LOOP UNTIL done%

_AUTODISPLAY 'back to normal
The option I showed helps in that if the timing of the main cycle is changed (with _limit or _timer, this is irrelevant now), then the movement and speed of the animations will remain unchanged. What you have shown is a possible solution to a fixed timing.
Reply




Users browsing this thread: 1 Guest(s)