Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. What are good pratices about games frame rates development
Forum Updated to NodeBB v4.3 + New Features

What are good pratices about games frame rates development

Scheduled Pinned Locked Moved Unsolved Game Development
2 Posts 2 Posters 368 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johngod
    wrote on 16 Aug 2024, 23:04 last edited by
    #1

    I am developing a qml game where I used a Timer with 60 fps for the game loop.
    Posts like this https://forum.qt.io/topic/60063/smooth-character-movement and Qt Blog https://www.qt.io/blog/new-in-qt-6.4-frameanimation-element, explain that Timers have flaws and can cause choppy animations with different monitors refresh rates.
    I naively replaced Timer with FrameAnimation, and character movement become smooth even with different monitors refresh rates.
    All good until last week, when I bought a new gaming laptop with 144Hz, and my character movement become blazing fast, which is not ok, since it should be consistent in different laptops with different frame rates.
    I read the FrameAnimation blog again with more attention and found I need to multiply the movement speed with frameTime. This seems to work, the following example is a moving cube, it seems to be at the same velocity in both my old and new laptops.

    import QtQuick
    
    Window {
        id: root
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        property real mm: Screen.pixelDensity
    
        Rectangle {
            id: rect2
            property real direction: 1
            //use the frameTime to make the velocity independent from different refresh rates
            property real speedWalk: 20 * mm * direction * frameAnimation.frameTime
    
            //velocity varies according different refresh rates
            //property real speedWalk: 1 * mm * direction
    
            width: 5 * mm
            height: width
            color: "orange"
            anchors.bottom: parent.bottom
    
            function move(){
                if (x > parent.width - rect2.width)
                    direction = -1
    
                if (x < 0)
                    direction = 1
    
                x += speedWalk
            }
        }
    
        FrameAnimation {
            id: frameAnimation
            running: true
            property real smoothfps: smoothFrameTime > 0 ? (1.0 / smoothFrameTime) : 0
            property real fps: frameTime > 0 ? (1.0 / frameTime) : 0
    
    
            onTriggered: {
                rect2.move()
            }
        }
    
        //property real speedNormalized: rect.speed * frameAnimation.frameTime
        Text {
            id: name
            text: " frameTime: " + frameAnimation.frameTime
            + "\n smoothFrameTime: "+frameAnimation.smoothFrameTime
            + "\n smooth fps: " + frameAnimation.smoothfps.toFixed(0)
            + "\n fps: " + frameAnimation.fps.toFixed(0)
            + "\n rectangle velocity: " + rect2.speedWalk//.toFixed(3)
        }
    
        MouseArea {
            anchors.fill: parent
            onClicked: frameAnimation.running = !frameAnimation.running
        }
    }
    

    Anything else I should know about frames rates, so I dont get any more surprises with my game? What are some other good practices that I am not aware ? How do other games platforms like Unity handle the frames rates differences ?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonSchroeder
      wrote on 19 Aug 2024, 07:01 last edited by
      #2

      Your speedWalk is not just dependent of the frameTime, but also of the pixelDensity. So far, this seems to be correct to include both of these. However, you might have a higher resolution monitor now instead of just having a faster one. Are you using a scaling factor (its a setting of your operating system)? You should also include Screen.devicePixelRatio. Not sure, if this is the actual problem.

      1 Reply Last reply
      0

      1/2

      16 Aug 2024, 23:04

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved