C
Qt Quick Ultralite layers Example
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
import QtQuick 2.15
import QtQuickUltralite.Layers 2.0
ImageLayer {
id: root
property real vx: 0
property real vy: 0
property Item container
Component.onCompleted: {
root.x = 1 + Math.floor(Math.random() * (container.width - root.width - 2))
root.y = 1 + Math.floor(Math.random() * (container.height - root.height - 2))
vx = Math.random() > 0.5 ? 1 : -1
vy = Math.random() > 0.5 ? 1 : -1
}
onTChanged: {
root.x += vx
root.y += vy
if (root.y <= 0 || root.y >= (container.height - root.height))
root.vy = -root.vy
if (root.x <= 0 || root.x >= (container.width - root.width))
root.vx = -root.vx
}
property real t: 0
NumberAnimation on t {
running: true
loops: Animation.Infinite
from: 0
to: 1
}
}