mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Adds support for scaling sprite physics groups
This commit is contained in:
parent
4187bcf90c
commit
ca724ae151
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user