Commit ca724ae1 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds support for scaling sprite physics groups

parent 4187bcf9
......@@ -51,6 +51,8 @@ class TestBed extends NodeWithSize {
TestBed() : super(new Size(1024.0, 1024.0)) {
_physicsNode = new PhysicsWorld(new Offset(0.0, 100.0));
PhysicsGroup group = new PhysicsGroup();
_physicsNode.addChild(group);
_obstacle = new Sprite(_spriteSheet["ship.png"]);
_obstacle.position = new Point(512.0, 800.0);
......@@ -62,7 +64,7 @@ class TestBed extends NodeWithSize {
friction: 0.5,
tag: "obstacle"
);
_physicsNode.addChild(_obstacle);
group.addChild(_obstacle);
_physicsNode.addContactCallback(myCallback, "obstacle", "ship", PhysicsContactType.begin);
// Animate obstacle
......
......@@ -277,15 +277,27 @@ class Node {
void set scale(double scale) {
assert(scale != null);
if (_physicsBody != null && parent is PhysicsWorld) {
PhysicsWorld physicsNode = parent;
physicsNode._updateScale(this.physicsBody, scale);
if (_physicsBody != null && (parent is PhysicsWorld || parent is PhysicsGroup)) {
_updatePhysicsScale(physicsBody, scale, parent);
}
_scaleX = _scaleY = scale;
invalidateTransformMatrix();
}
void _updatePhysicsScale(PhysicsBody body, double scale, Node physicsParent) {
if (physicsParent == null) return;
if (physicsParent is PhysicsWorld) {
PhysicsWorld world = physicsParent;
world._updateScale(body, scale);
} else if (physicsParent is PhysicsGroup) {
_updatePhysicsScale(body, scale * physicsParent.scale, physicsParent.parent);
} else {
assert(false);
}
}
/// The horizontal scale of this node relative its parent.
///
/// myNode.scaleX = 5.0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment