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 + box2d + dynamical object creation from js file
QtWS25 Last Chance

Qml + box2d + dynamical object creation from js file

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.7k Views
  • 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 Offline
    L Offline
    longWorm
    wrote on last edited by
    #1

    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
    0
    • L Offline
      L Offline
      longWorm
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        mikealfa
        wrote on last edited by
        #3

        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
        0
        • L Offline
          L Offline
          longWorm
          wrote on last edited by
          #4

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

          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