March 10, 2012

mikealfa mikealfa
Lab Rat
35 posts

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 contact

the codes of Ball and Star are as follows

****Ball****

  1. Item{
  2.   Image {
  3.   id: ball
  4.     x: -8
  5.     y: 18
  6.  
  7.     source: "images/ball8.png"
  8.     signal clicked()
  9.  
  10.     MouseArea{
  11.         id:ballMouse
  12.         anchors.fill:parent
  13.     }
  14.  
  15.  
  16.  
  17.  
  18.     RotationAnimation on rotation {
  19.     from: 0
  20.     to: 360
  21.     direction: RotationAnimation.Clockwise
  22.     duration: 1200
  23.     loops: Animation.Infinite
  24.     }
  25. }
  26. }

****Star****

  1. Item{
  2.     id:item
  3.  
  4. Image {
  5.     id: star
  6.     rotation: 0
  7.     source: "images/star.png"
  8.     RotationAnimation on rotation {
  9.         from:0
  10.         to:360
  11.         duration:1000
  12.         loops:Animation.Infinite
  13.     }
  14.     signal clicked()
  15.  
  16.     MouseArea{
  17.         id:starMouse
  18.         anchors.fill:parent
  19.         onClicked: starAnimation.running = true
  20.     }
  21.  
  22.     ParallelAnimation{
  23.         id:starAnimation
  24. SequentialAnimation{
  25.             NumberAnimation{
  26.                 target:star
  27.                 property:"x"
  28.                 from:star.x
  29.                 to:star.x-80
  30.             }
  31. }
  32. SequentialAnimation{
  33.             NumberAnimation{
  34.                 target:star
  35.                 property:"y"
  36.                 from:star.y
  37.                 to:star.y-80
  38.             }
  39. }
  40.         SequentialAnimation{
  41.         NumberAnimation{
  42.             target:star
  43.             property:"opacity"
  44.             to:0.8
  45.  
  46.         }
  47.         NumberAnimation{
  48.             target:star
  49.             property:"opacity"
  50.             to:0.6
  51.         }
  52.         NumberAnimation{
  53.             target:star
  54.             property:"opacity"
  55.             to:0.4
  56.         }
  57.         NumberAnimation{
  58.             target:star
  59.             property:"opacity"
  60.             to:0.2
  61.         }
  62.         NumberAnimation{
  63.             target:star
  64.             property:"opacity"
  65.             to:00
  66.         }
  67.         }
  68.         SequentialAnimation{
  69.             NumberAnimation{
  70.                 target:star
  71.                 property:"scale"
  72.                 to:1.2
  73.             }
  74.             NumberAnimation{
  75.                 target:star
  76.                 property:"scale"
  77.                 to:1.4
  78.             }
  79.             NumberAnimation{
  80.                 target:star
  81.                 property:"scale"
  82.                 to:1.6
  83.             }
  84.             NumberAnimation{
  85.                 target:star
  86.                 property:"scale"
  87.                 to:1.8
  88.             }
  89.             NumberAnimation{
  90.                 target:star
  91.                 property:"scale"
  92.                 to:2.0
  93.             }
  94.         }
  95.  
  96.         running:false
  97.     }
  98.  
  99. }
  100. }

15 replies

March 10, 2012

Eddy Eddy
Gene Splicer
1533 posts

Could you please use @-code tags. that makes it much more readable for us.

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

March 10, 2012

mikealfa mikealfa
Lab Rat
35 posts

yep…did so :)

March 10, 2012

mikealfa mikealfa
Lab Rat
35 posts

how to detect the collisions of two objects and implement a set of animations accordingly ?

March 10, 2012

task_struct task_struct
Ant Farmer
349 posts

Hello,

you can use Box 2D qml plugin [gitorious.org]

 Signature 

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds

March 11, 2012

mikealfa mikealfa
Lab Rat
35 posts

hello everyone…
how can i detect the collision of two objects and implement a logic accordingly ?

March 11, 2012

timoph timoph
Lab Rat
17 posts

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.

March 11, 2012

Eddy Eddy
Gene Splicer
1533 posts

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.

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

March 11, 2012

mikealfa mikealfa
Lab Rat
35 posts

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 :(

March 11, 2012

mikealfa mikealfa
Lab Rat
35 posts

@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

March 11, 2012

Eddy Eddy
Gene Splicer
1533 posts

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.

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

March 11, 2012

mikealfa mikealfa
Lab Rat
35 posts

hey come on….
u r too fast !

March 13, 2012

mikealfa mikealfa
Lab Rat
35 posts

to: task_struct
hey….can u tell me how to use the box2d plugin to detect collisions for my

  1. Ball
and
  1. Star
objects ?

March 13, 2012

task_struct task_struct
Ant Farmer
349 posts

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

 Signature 

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds

March 18, 2012

mikealfa mikealfa
Lab Rat
35 posts

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

March 19, 2012

task_struct task_struct
Ant Farmer
349 posts

Hello,

You shoud have something like this:

  1. Body {
  2.         id: someBody
  3.  
  4.         fixtures: Circle {
  5.                 id: circle
  6.  
  7.                 radius: 10
  8.                 density: 6
  9.                 friction: 0.7
  10.                 restitution: 0.4
  11.  
  12.                 onBeginContact: {
  13.                         // put here your code
  14.                 }
  15.         }
  16. }

 Signature 

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds

 
  ‹‹ [solved] Symbian^3 ToolBarLayout bug      Is it possible to stream local file using QML ? ››

You must log in to post a reply. Not a member yet? Register here!