Change vertices in box2d polygon
hi, everybody.
i’m writing game, using qml & box2d. there’s file containing box2d polygon and image:
- import QtQuick 1.0
- import Box2D 1.0
- Body {
- id: block
- fixedRotation: false
- sleepingAllowed: false
- bodyType: Body.Static
- property variant __x: []
- property variant __y: []
- property alias image: image.source
- function setBlock(x,y)
- {
- __x = x;
- __y = y;
- polygon.vertices = [
- ];
- }
- fixtures: Polygon {
- id: polygon
- anchors.fill: parent
- density: 0;
- friction: 10;
- restitution: 1;
- vertices: [
- ]
- }
- Image {
- id: image
- x: __x[2]
- y: __y[1]
- width: __x[0] - __x[2]
- height: __y[0] - __y[1]
- fillMode: Image.Tile
- source: "../../img/block_.png"
- }
- Behavior on x { SmoothedAnimation { velocity: 300 } }
- Behavior on y { SmoothedAnimation { velocity: 300 } }
- }
i create it dymanically from javascript like this:
- var dynamicObject = block.createObject(world,{"__x": var_1,"__y":var_2});
If i try to change vertices, using setBlock() method polygon’s coordinates stay the same, only image changes.
Does somebody know what to do?
1 reply
I’ve found that it’s possible to recreate object with new vertices:
- blockArray[i].destroy();
- if (block.status == Component.Ready) {
- var dynamicObject = block.createObject(world,{"__x": x,"__y": y});
- blockArray[i] = dynamicObject;
- }
But it’s not the solution of problem, it’s just the way to make it work
You must log in to post a reply. Not a member yet? Register here!
