Hi Florian,
here is a small example how to decrease the height of a “smashable” box everytime another box drops on it.
Box.qml
import QtQuick 1.1
import Box2D 1.0
import VPlay 1.0
EntityBase {
id: entity
entityType: "box"
width: 32
height: 32
BoxCollider {
id: boxCollider
anchors.fill: parent
// restitution is bounciness
fixture.restitution: 0.8
fixture.onBeginContact: {
if(variationType != "smashable") return;
var fixture = other;
var body = fixture.parent;
var component = body.parent;
var collidedEntity = component.owningEntity;
var collidedEntityType = collidedEntity.entityType;
var collidedEntityVariationType = collidedEntity.variationType;
if(collidedEntityType === "box" && entity.height > 5) {
entity.height = entity.height-3;
}
}
}
Rectangle {
id: sprite
color: "blue"
anchors.fill: parent
}
}
main.qml
import VPlay 1.0
import QtQuick 1.1
import "entities"
GameWindow {
id: window
EntityManager {
id: entityManager
}
Scene {
id: scene
PhysicsWorld {gravity.y: -10}
Box {
x: 100
}
Box {
x: 100
y: 300
variationType: "smashable"
}
EntityBase {
id: ground
entityType: "ground"
height: 5
anchors.left: scene.left
anchors.right: scene.right
anchors.bottom: scene.bottom
Rectangle {
color: "red"
anchors.fill: parent
}
BoxCollider {
anchors.fill: parent
bodyType: Body.Static
}
}
}
}
Is this kind of what you are looking for?
Cheers,
Alex