Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit eb2709e

Browse files
committed
Merge pull request #1506 from vlidholt/master
Fixes to demo game
2 parents ed041a2 + bf4342f commit eb2709e

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

examples/game/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ class GameDemoState extends State<GameDemo> {
119119
width: 128.0,
120120
height: 128.0
121121
),
122-
new Text(
123-
"Last Score: $_lastScore",
122+
new DefaultTextStyle(
123+
child: new Text(
124+
"Last Score: $_lastScore"
125+
),
124126
style: new TextStyle(fontSize:20.0)
125127
)
126128
],

skysprites/lib/physics_body.dart

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class PhysicsBody {
99
PhysicsBody(this.shape, {
1010
this.tag: null,
1111
this.type: PhysicsBodyType.dynamic,
12-
this.density: 1.0,
13-
this.friction: 0.0,
14-
this.restitution: 0.0,
15-
this.isSensor: false,
12+
double density: 1.0,
13+
double friction: 0.0,
14+
double restitution: 0.0,
15+
bool isSensor: false,
1616
this.linearVelocity: Offset.zero,
1717
this.angularVelocity: 0.0,
1818
this.linearDampening: 0.0,
@@ -23,18 +23,74 @@ class PhysicsBody {
2323
this.bullet: false,
2424
this.active: true,
2525
this.gravityScale: 1.0
26-
});
26+
}) {
27+
this.density = density;
28+
this.friction = friction;
29+
this.restitution = restitution;
30+
this.isSensor = isSensor;
31+
}
2732

2833
Object tag;
2934

3035
PhysicsShape shape;
3136

3237
PhysicsBodyType type;
3338

34-
double density;
35-
double friction;
36-
double restitution;
37-
bool isSensor;
39+
double _density;
40+
41+
double get density => _density;
42+
43+
set density(double density) {
44+
_density = density;
45+
46+
if (_body == null)
47+
return;
48+
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
49+
f.setDensity(density);
50+
}
51+
}
52+
53+
double _friction;
54+
55+
double get friction => _friction;
56+
57+
set friction(double friction) {
58+
_friction = friction;
59+
60+
if (_body == null)
61+
return;
62+
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
63+
f.setFriction(friction);
64+
}
65+
}
66+
67+
double _restitution;
68+
69+
double get restitution => _restitution;
70+
71+
set restitution(double restitution) {
72+
_restitution = restitution;
73+
74+
if (_body == null)
75+
return;
76+
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
77+
f.setRestitution(restitution);
78+
}
79+
}
80+
81+
bool _isSensor;
82+
83+
bool get isSensor => _isSensor;
84+
85+
set isSensor(bool isSensor) {
86+
_isSensor = isSensor;
87+
88+
if (_body == null)
89+
return;
90+
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
91+
f.setSensor(isSensor);
92+
}
93+
}
3894

3995
Offset linearVelocity;
4096
double angularVelocity;

0 commit comments

Comments
 (0)