Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › thinking qt

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #14916

    Bas

    hi,

    i am having trouble thinking the QT way of animating/doing things.

    in other game or environments there is mostly a game loop routine where you can manage things.

    the hard part and maybe something to foucs on, is the translation of other game engines way of handling things.

    and the way Felgo is handling things.

    like everything needs to be an animation?

    today i ran into such a thinking difference.
    i wanted to create a spinner in QML where 4 round re3cts would spin in a different way around eacother.
    my way of thinking is Timer -> trigger function and then calculate Sine and cosine functions to handle the rotation.
    but it did not perform.
    i ended up with 4 rectangles with rounded sub rectangles wich rotates etc.

     

    so my point is that i am having difficulties in translating from an certain way of doing things into another way of doing things, solving the problem
    of animating the right way in Felgo.

    maybe i am not the only one who is facing this.

    I don’t have a solution at the moment, but i try to figure this out.

    just a word.

    Bas

     

    #14928

    Günther
    Felgo Team

    Hi Bas!

    I think that this actually applies to every framework/technology/solution in general. The used concepts and architecture-decisions always result in a certain way how things work together and can be used.

    Of course, this also implies that some use-cases are a perfect fit while others feel more like a “workaround” than a beautiful solution.
    I believe that the Animations in Qt are very easy to use, flexible and perfectly follow “the Qt way of things” – as you call it.

    The thing is, “the Qt way of things” might not be the best solution for every problem, which I guess is the case for the spinning Rectangles you want to do. I’m sorry to say there’s also no simple solution or hint that I can point you to at the moment. Maybe the C++ side of Qt allows a more suitable solution than using QML Timers and Animations.

    In any case, feel free to share your insights or solution with us here in the forum!

    Good luck and (hopefully) also much fun! 😉
    Günther

     

    #14953

    Bas

    ok, what i learned from the implementation of spine in QML is that animations are fast.

    so what i wanted to do was to let a series sprites fly to some random points and follow each other.

    with speed in mind I figured out the following:

    I needed a Dynamic creation of a path:

    PathCreator.qml

    import Felgo 3.0
    import QtQuick 2.7
    
    Item {
    
        id: item
    
        property variant arr : []
        property variant path : null
        property int startx : 0
        property int starty : 0
    
        function createObject() {
            var len=arr.length,i,s = 'import QtQuick 2.7; Path {'+ "\n"
            s += ' startX:' + startx + '; ' + "\n"
            s += ' startY:' + starty + '; '+ "\n"
            for(i=0;i<len;i++) {
                s += ' PathCurve { x: ' + arr[i].xp + '; y:' + arr[i].yp + ' }' + "\n";
                s += ' PathAttribute { name: "myscale"; value:' + arr[i].s + ' }' + "\n";
            }
            s += '}'+ "\n"
    
            console.log(s)
            path = Qt.createQmlObject( s, item);
        }
    
    }
    

     

    And i wanted an enemy to follow that path:

    Enemy1.qml

    import Felgo 3.0
    import QtQuick 2.7
    
    EntityBase {
    
        entityId: "enemy1"
        entityType: "enemy"
    
        id: item
    
        property variant myPath : null
        property alias pathAnim : pAnim
    
        property double imgScale: 0.4
        property int delay: 0
        property int animTime: 10000
    
        Image {
            id:img
            source:"../../assets/gfx/enemy1/enemy1.png"
            scale: imgScale
        }
    
        BoxCollider {
            anchors.fill: img
        }
        SequentialAnimation {
            id:seqAnim
            PauseAnimation { duration: delay }
            PathAnimation {
                id:pAnim
                target: item
                path : myPath
                duration: animTime
            }
            //        running:true
        }
        Component.onCompleted:  {
            start()
        }
    
        function start() {
            seqAnim.start()
        }
    }
    

     

     

    and some kind of level Manager who will manage paths and triggers off the enemies

    import Felgo 3.0
    import QtQuick 2.7
    import "../common"
    
    Item {
    
        id: item
    
        anchors.fill: gameWindowAnchorItem
    
        property variant scene : null
        property variant path1
        property variant enemies : []
    
        PathCreator {
            id:p1
        }
    
        function createRndPath() {
            var i;
            p1.startx = scene.width + 300
            p1.starty = scene.height >> 1
            for(i=0;i<20;i++) {
                p1.arr.push( {xp:200 + parseInt(Math.random()*scene.width-200), yp:150+parseInt(Math.random()*scene.height-300), s:Math.random()} )
            }
            p1.arr.push( {xp:p1.startx, yp:p1.starty, s:1} )
            p1.createObject();
        }
    
        function createEneies1() {
            //-- create enemies
            var i
            for (i=0;i<10;i++) {
                var en = Qt.createComponent("Enemy1.qml");
                en.createObject( item, {myPath:p1.path, delay:100*i, x:p1.startx, y:p1.starty, z:100-i})
                enemies.push( en );
            }
        }
    
        Component.onCompleted: {
            createRndPath()
            createEneies1()
        }
    }
    

     

    i have a box collider in the enemy and that causes some sprites to be visible in the startup

    when i remove the boxcollider everysprite starts outside the screen on the right side.

    here is my PhysicsWorld code:

        PhysicsWorld {
            id: world
            // physics is disabled initially, and enabled after the splash is finished
            running: true
            gravity.y: 9.81
            z: 10 // draw the debugDraw on top of the entities
    
            // these are performance settings to avoid boxes colliding too far together
            // set them as low as possible so it still looks good
            updatesPerSecondForPhysics: 60
            velocityIterations: 5
            positionIterations: 5
            debugDrawVisible: true
        }
    

     

     

     

    #14954

    Bas

    hmm i see that i have choosen a name for the function to create the Path

    createObject, but his is also an internal function so it would be better to name it createPath

    import Felgo 3.0
    import QtQuick 2.7
    
    Item {
    
        id: item
    
        property variant arr : []
        property variant path : null
        property int startx : 0
        property int starty : 0
    
        function createPath() {
            var len=arr.length,i,s = 'import QtQuick 2.7; Path {'+ "\n"
            s += ' startX:' + startx + '; ' + "\n"
            s += ' startY:' + starty + '; '+ "\n"
            for(i=0;i<len;i++) {
                s += ' PathCurve { x: ' + arr[i].xp + '; y:' + arr[i].yp + ' }' + "\n";
                s += ' PathAttribute { name: "myscale"; value:' + arr[i].s + ' }' + "\n";
            }
            s += '}'+ "\n"
    
            console.log(s)
            path = Qt.createQmlObject( s, item);
        }
    }
    

     

     

    #14955

    Bas
    #14957

    Günther
    Felgo Team

    Hi Bas!

    The colliders do not always exactly match the given entity size and position as they are also optimized to include movement and speed for an improved collision detection (e.g. to avoid troubles like a small collider that moves fast and moves/jumps through another collider from one frame to the next).

    As long as the game behaves / plays the way you want some visible differences between colliders and the entities should be no problem.

    Best,
    Günther

    #14960

    Marcin

    Hi all,
    So Bas, you are not the only one.
    Apart from standard “why do I even use Qt for games(whenever I mention it)” I, on my own, have issues to translate things.
    Definitely is not that easy for me to translate some tutorials into Qt but I also really like how Qt works.
    It would take me some time to switch to a different tool.

    V-play libraries are nice but they add some game specific features to a tool/set of libraries, which are not only for games.
    There is not much more to add here than what Günther already said.

Viewing 7 posts - 1 through 7 (of 7 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded