Qml + box2d + dynamical object creation from js file
-
Hello, everyone.
I need to dynamically load some objects declared in qml files.Here is star object:
@import QtQuick 1.0
import Box2D 1.0Body {
id: star
fixedRotation: false
sleepingAllowed: false
bodyType: Body.Staticfixtures: 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: planetfixedRotation: 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 -
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 :(