Collision detection for Animation? [Solved]
-
Is it possible to add collision detection to animation so that it launches every time the animation moves?
Example if you have PropertyAnimation on x { from: 0; to:100; duration 1000}
Is it somehow possible to bind for example PropertyChange on x to that animation?Or is there any other way to make good collision detection, if you create timer, it doesn't take all pixels.. and it lags when your phone lags..
-
You could try performing the collision detection in the onXChanged handler:
@onXChanged: detectCollisions()@
Depending on what you are making, you might also be able to make use of something like http://gitorious.org/qml-box2d (QML bindings for Box2D).
Regards,
Michael -
I tried to use onXChanged, but animation didn't trigger it.
-
Hmm, it should be triggered -- can you check if the following works for you? (it should print lots of messages to the console)
@import QtQuick 1.0
Rectangle {
width: 400
height: 400Rectangle { id: rect width: 100 height: 100 color: "red" PropertyAnimation on x { from: 0; to: 100; duration: 1000 } onXChanged: console.log("x changed to " + x) }
}@
Regards,
Michael -
Hey, thanks. It was Behaviour on x, that I had tried earlier!
onXChanged worked like a charm, thanks!