QML Game Implementation
-
I have an element Ball and element Star...
How can i make the Star perform a little animation whenever the Ball comes in contactthe codes of Ball and Star are as follows
Ball
@Item{
Image {
id: ball
x: -8
y: 18source: "images/ball8.png" signal clicked() MouseArea{ id:ballMouse anchors.fill:parent } RotationAnimation on rotation { from: 0 to: 360 direction: RotationAnimation.Clockwise duration: 1200 loops: Animation.Infinite }
}
}@Star
@Item{
id:itemImage {
id: star
rotation: 0
source: "images/star.png"
RotationAnimation on rotation {
from:0
to:360
duration:1000
loops:Animation.Infinite
}
signal clicked()MouseArea{ id:starMouse anchors.fill:parent onClicked: starAnimation.running = true } ParallelAnimation{ id:starAnimation
SequentialAnimation{
NumberAnimation{
target:star
property:"x"
from:star.x
to:star.x-80
}
}
SequentialAnimation{
NumberAnimation{
target:star
property:"y"
from:star.y
to:star.y-80
}
}
SequentialAnimation{
NumberAnimation{
target:star
property:"opacity"
to:0.8} NumberAnimation{ target:star property:"opacity" to:0.6 } NumberAnimation{ target:star property:"opacity" to:0.4 } NumberAnimation{ target:star property:"opacity" to:0.2 } NumberAnimation{ target:star property:"opacity" to:00 } } SequentialAnimation{ NumberAnimation{ target:star property:"scale" to:1.2 } NumberAnimation{ target:star property:"scale" to:1.4 } NumberAnimation{ target:star property:"scale" to:1.6 } NumberAnimation{ target:star property:"scale" to:1.8 } NumberAnimation{ target:star property:"scale" to:2.0 } } running:false }
}
}
@ -
Hello,
you can use "Box 2D qml plugin":http://gitorious.org/qml-box2d
-
AFAIK there's no straightforward way to do it. You can expose the underlaying QGraphicsItem stuff and use collidesWith() etc from there or you can implement your own collision detection based on item coordinates (could be a bit expensive operation). Dunno if there are examples floating on this floating around somewhere.
If someone has a nice and clean example for this, please share.
-
I am making a game FastBall actually trying to implement the ipad game fastball2....
in the game we have a horizontal path on which there are stars and obstacles...
the user gains points by collecting stars and game gets over if hits obstacles...Well, i have implemented the Ball Module, the *stars8 and the individual obstacles modules by QML...
i have also implemented the ball to jump when clicked...I have given an animation to the star and set the running property false and i have the animations to take place when the Ball moves over the star and the Ball to disappear when hits the obstacles...
just stuck over here...how can i do that :(
-
Hello,
It's pretty easy. You create a World and Bodies for star and ball( may be the best fixture will be Circle ). To detect collisions you can use fixture's signal beginContact
For examples, see http://gitorious.org/qml-box2d/qml-box2d/trees/master/examples
I can't find detailed documentation so I use source code. You can look at headers to see what different types can do. In QML all Q_PROPERTYs are visible, also you can connect to every signal, and you can call every function that starts with macro Q_INVOKABLE
-
Hello,
You shoud have something like this:
@
Body {
id: someBodyfixtures: Circle { id: circle radius: 10 density: 6 friction: 0.7 restitution: 0.4 onBeginContact: { // put here your code } }
}
@