I don't understand what you mean, sorry... I'm sure the solution I offered to you is the proper way to go.
Edit:
Somewhat silly example but it works:
import QtQuick 1.1
Rectangle {
property bool hit: false
function hitTest(posX, posY) {
// dirty hit test
if(posX >= obstacle.x && posY <= obstacle.x+obstacle.width
&& posY >= obstacle.y && posY <= obstacle.y+obstacle.height) {
root.hit = true
} else {
root.hit = false
}
}
id: root
width: 360
height: 360
MouseArea {
anchors.fill: parent
onPositionChanged: hitTest(mouse.x, mouse.y)
onReleased: root.hit = false
}
Rectangle {
id: obstacle
x: 200
y: 100
width: 50
height: width
radius: width/2
color: root.hit ? "red" : "blue"
Behavior on x {
NumberAnimation { duration: 500 }
}
Behavior on y {
NumberAnimation { duration: 500 }
}
}
Text {
visible: hit
text: "Collision detected"
anchors.left: parent.left
anchors.bottom: parent.bottom
}
Timer {
triggeredOnStart: true
interval: 500
running: true
onTriggered: {
obstacle.x = Math.max(0, Math.min(obstacle.x - 10 + Math.round(Math.random() *20), root.width))
obstacle.y = Math.max(0, Math.min(obstacle.y - 10 + Math.round(Math.random() *20), root.height))
}
repeat: true
}
}
import QtQuick 1.1
Rectangle {
property bool hit: false
function hitTest(posX, posY) {
// dirty hit test
if(posX >= obstacle.x && posY <= obstacle.x+obstacle.width
&& posY >= obstacle.y && posY <= obstacle.y+obstacle.height) {
root.hit = true
} else {
root.hit = false
}
}
id: root
width: 360
height: 360
MouseArea {
anchors.fill: parent
onPositionChanged: hitTest(mouse.x, mouse.y)
onReleased: root.hit = false
}
Rectangle {
id: obstacle
x: 200
y: 100
width: 50
height: width
radius: width/2
color: root.hit ? "red" : "blue"
Behavior on x {
NumberAnimation { duration: 500 }
}
Behavior on y {
NumberAnimation { duration: 500 }
}
}
Text {
visible: hit
text: "Collision detected"
anchors.left: parent.left
anchors.bottom: parent.bottom
}
Timer {
triggeredOnStart: true
interval: 500
running: true
onTriggered: {
obstacle.x = Math.max(0, Math.min(obstacle.x - 10 + Math.round(Math.random() *20), root.width))
obstacle.y = Math.max(0, Math.min(obstacle.y - 10 + Math.round(Math.random() *20), root.height))
}
repeat: true
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks