Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: sky/examples/game/lib/node.dart

Issue 1179333002: Playable demo game and bug fixes in sprites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/examples/game/lib/node.dart
diff --git a/sky/examples/game/lib/node.dart b/sky/examples/game/lib/node.dart
index d8cfc28599a1156b8543b95e577a5700e243eeaf..1db9cf20463f9dd80c28b04b798a182f3c9343bf 100644
--- a/sky/examples/game/lib/node.dart
+++ b/sky/examples/game/lib/node.dart
@@ -1,8 +1,8 @@
part of sprites;
-double degrees2radians(double degrees) => degrees * Math.PI/180.8;
+double convertDegrees2Radians(double degrees) => degrees * Math.PI/180.8;
-double radians2degrees(double radians) => radians * 180.0/Math.PI;
+double convertRadians2Degrees(double radians) => radians * 180.0/Math.PI;
class Node {
@@ -28,19 +28,22 @@ class Node {
int _childrenLastAddedOrder;
bool _childrenNeedSorting;
+ bool paused = false;
+
List<Node>_children;
// Constructors
Node() {
_rotation = 0.0;
- _position = new Point(0.0, 0.0);
+ _position = Point.origin;
_scaleX = _scaleY = 1.0;
_isMatrixDirty = false;
_transformMatrix = new Matrix4.identity();
_children = [];
_childrenNeedSorting = false;
_childrenLastAddedOrder = 0;
+ _zPosition = 0.0;
visible = true;
}
@@ -107,7 +110,7 @@ class Node {
void removeFromParent() {
assert(_parent != null);
- _parent.removeFromParent();
+ _parent.removeChild(this);
}
void removeAllChildren() {
@@ -135,8 +138,8 @@ class Node {
sy = 0.0;
}
else {
- double radiansX = degrees2radians(_rotation);
- double radiansY = degrees2radians(_rotation);
+ double radiansX = convertDegrees2Radians(_rotation);
+ double radiansY = convertDegrees2Radians(_rotation);
cx = Math.cos(radiansX);
sx = Math.sin(radiansX);
@@ -157,19 +160,29 @@ class Node {
// Transforms to other nodes
Matrix4 _nodeToBoxMatrix() {
+ assert(_spriteBox != null);
+
Matrix4 t = transformMatrix;
+ // Apply transforms from parents
Node p = this.parent;
while (p != null) {
t = new Matrix4.copy(p.transformMatrix).multiply(t);
p = p.parent;
}
+
+ // Apply transform from sprite box
+ t = new Matrix4.copy(_spriteBox.transformMatrix).multiply(t);
+
return t;
}
Matrix4 _boxToNodeMatrix() {
+ assert(_spriteBox != null);
+
Matrix4 t = _nodeToBoxMatrix();
t.invert();
+
return t;
}
@@ -223,12 +236,8 @@ class Node {
void prePaint(PictureRecorder canvas) {
canvas.save();
- // TODO: Can this be done more efficiently?
// Get the transformation matrix and apply transform
- List<double> matrix = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
- this.transformMatrix.copyIntoArray(matrix);
- Float32List list32 = new Float32List.fromList(matrix);
- canvas.concat(list32);
+ canvas.concat(transformMatrix.storage);
abarth-chromium 2015/06/13 00:03:20 \o/
}
void paint(PictureRecorder canvas) {
@@ -240,7 +249,7 @@ class Node {
if (_childrenNeedSorting) {
_children.sort((Node a, Node b) {
if (a._zPosition == b._zPosition) {
- return b._addedOrder - a._addedOrder;
+ return a._addedOrder - b._addedOrder;
}
else if (a._zPosition > b._zPosition) {
return 1;
@@ -263,6 +272,8 @@ class Node {
// Receiving update calls
void update(double dt) {
+ }
+ void spriteBoxPerformedLayout() {
}
}

Powered by Google App Engine
This is Rietveld 408576698