Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qml + box2d + dynamical object creation from js file

    QML and Qt Quick
    2
    4
    2485
    Loading More Posts
    • 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.
    • L
      longWorm last edited by

      Hello, everyone.
      I need to dynamically load some objects declared in qml files.

      Here is star object:
      @import QtQuick 1.0
      import Box2D 1.0

      Body {
      id: star
      fixedRotation: false
      sleepingAllowed: false
      bodyType: Body.Static

      fixtures: Circle {
          id: circle
          radius: 50
          anchors.fill: parent
          density: 0;
          friction: 10;
          restitution: 1;
      }
      
      Image {
              id: circleRect
      
              anchors.centerIn: parent
              width: circle.radius * 2
              height: width
              smooth: true
              source: "../../img/star.png"
      }
      

      }
      @
      And planet:
      @
      Body {
      id: planet

      fixedRotation: false
      sleepingAllowed: false
      
      fixtures: Circle {
          id: circle
          radius: 8
          anchors.fill: parent
          density: 0;
          friction: 10;
          restitution: 1;
      }
      
      Image {
              id: circleRect
      
              anchors.centerIn: parent
              width: circle.radius * 2
              height: width
              smooth: true
              source: "../../img/planet.png"
      }
      

      }
      @
      Planet declared in main qml file. When i declare star in the same file as planet, everything works fine: planet bounce off if they collide.
      @
      ......
      Star{
      id: star1
      x: 0
      y: 0
      }
      .......
      @
      But if i dynamically load star from js file, it behaves like image(not like static body): planet just pass through it.
      @
      ......
      // Add star to screen
      var star = Qt.createComponent("Star.qml");
      if (star.status == Component.Ready) {
      var dynamicObject = star.createObject(screen);
      dynamicObject.x = x;
      dynamicObject.y = y;

          if(starsCount)
              starsObjectArray.push(star);
          else
              starsObjectArray[0] = dynamicObject;
      }
      

      .......
      @
      Any ideas? Thanks for your attention

      1 Reply Last reply Reply Quote 0
      • L
        longWorm last edited by

        I found error while i was looking at my post=)

        I added star to Rectangle qml element, not to World box2d element.
        Sorry

        1 Reply Last reply Reply Quote 0
        • M
          mikealfa last edited by

          hey...
          i have two objects...
          A Star and a ball....and i want the Star to perform a set of animations when the Ball comes in contact with the Star..
          can u tell me how to do so by using the Box2D qml plugin....
          since no documentation is available its been tough to understand how it works :(

          1 Reply Last reply Reply Quote 0
          • L
            longWorm last edited by

            i'm looking for it myself)) i'll post if i find anything.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post