Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Game Implementation

QML Game Implementation

Scheduled Pinned Locked Moved QML and Qt Quick
16 Posts 4 Posters 8.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikealfa
    wrote on last edited by
    #1

    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
    @Item{
    Image {
    id: ball
    x: -8
    y: 18

    source: "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:item

    Image {
    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
    }
    

    }
    }
    @

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

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

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikealfa
        wrote on last edited by
        #3

        yep...did so :)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mikealfa
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            task_struct
            wrote on last edited by
            #5

            Hello,

            you can use "Box 2D qml plugin":http://gitorious.org/qml-box2d

            "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."

            • Linu...
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mikealfa
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • T Offline
                T Offline
                timoph
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  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.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mikealfa
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mikealfa
                      wrote on last edited by
                      #10

                      @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

                      1 Reply Last reply
                      0
                      • EddyE Offline
                        EddyE Offline
                        Eddy
                        wrote on last edited by
                        #11

                        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.

                        Qt Certified Specialist
                        www.edalsolutions.be

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mikealfa
                          wrote on last edited by
                          #12

                          hey come on....
                          u r too fast !

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mikealfa
                            wrote on last edited by
                            #13

                            to: task_struct
                            hey....can u tell me how to use the box2d plugin to detect collisions for my @Ball@ and @Star@ objects ?

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              task_struct
                              wrote on last edited by
                              #14

                              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

                              "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."

                              • Linu...
                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mikealfa
                                wrote on last edited by
                                #15

                                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

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  task_struct
                                  wrote on last edited by
                                  #16

                                  Hello,

                                  You shoud have something like this:

                                  @
                                  Body {
                                  id: someBody

                                      fixtures: Circle {
                                              id: circle
                                  
                                              radius: 10
                                              density: 6
                                              friction: 0.7
                                              restitution: 0.4
                                  
                                              onBeginContact: {
                                                      // put here your code
                                              }
                                      }
                                  

                                  }
                                  @

                                  "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."

                                  • Linu...
                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved