Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QmL Random Scale Animation
Forum Updated to NodeBB v4.3 + New Features

QmL Random Scale Animation

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.9k 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.
  • O Offline
    O Offline
    omar.msk
    wrote on 21 Feb 2015, 04:06 last edited by
    #1

    i'm trying to create a way to make an image change randomly its scale. i need both the function that provides the random scale and the animation between the scales to be working. But it only does it the first time, any ideas why?

    if you know a easy way to do it i will appreciate that

    @import QtQuick 2.2
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.1

    Rectangle {
    id: container;
    width: 700
    height: 700

    function randomscales()
    {
        var scalesArray = [1, 1,1, 1.1, 0.9, 1.2, 0.8,0.7]
        var randomNumber;
        var actualStateNumber
        do{
            randomNumber = Math.floor(Math.random()*scalesArray.length);
        }
        while (randomNumber == actualStateNumber);
        actualStateNumber = randomNumber;
        return scalesArray[randomNumber];
    }
    
    Timer{
        id: count1
        interval: 500
        running: true
        repeat: true
        onTriggered: {
            scaleAnimation.start()
            randomscales.start()
        }
    }
    
    Image {
        id: flor;
        source: "flor.png";
        x: 100
        y: 100
        scale: 1
    
        transform: Scale {
            id: scaleTransform
            property real scale: 1
            xScale: scale
            yScale: scale
            origin.x: 96
            origin.y: 104
        }
    
        SequentialAnimation {
            id: scaleAnimation
            loops: 1
            PropertyAnimation {
                target: scaleTransform
                properties: "scale"
                to: randomscales()
                duration: 500
            }
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 21 Feb 2015, 07:43 last edited by
      #2

      Hi,

      Starting the animation wont re-evaluate the binding and hence it wont update the to value. Instead you can
      @
      onTriggered: {
      propAnimation.to = randomscales() //propAnimation = id of PropertyAnimation
      scaleAnimation.start()
      }
      @

      Also randomscales.start() is wrong.

      157

      1 Reply Last reply
      0

      1/2

      21 Feb 2015, 04:06

      • 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