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 }
}
}
@ -
Could you please use @-code tags. that makes it much more readable for us.
-
yep...did so :)
-
how to detect the collisions of two objects and implement a set of animations accordingly ?
-
Hello,
you can use "Box 2D qml plugin":http://gitorious.org/qml-box2d
-
hello everyone...
how can i detect the collision of two objects and implement a logic accordingly ? -
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.
-
Please don't start new topics on the same subject over and over again. Please give us some time to respond. Not everybody is always active. It's weekend you know;-)
I Merged the 3 threads.
-
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 :(
-
@eddy
m really sorry but i guess u may have to merge one more thread to this..
m really sorry but just got stuck here and jus wanna to move way ahead -
I just merged number 4.
Thanks for the hint ;-)
If you have new info to add or more specific questions it is recommended to continue in the same topic. People will eventually read them. Some patience helps.
-
hey come on....
u r too fast ! -
to: task_struct
hey....can u tell me how to use the box2d plugin to detect collisions for my @Ball@ and @Star@ objects ? -
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
-
hey tas but how to use the beginContact signal...i tried using it bt guess m messing lil with its syntax...unable to get output
-
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 } }
}
@