| OLD | NEW |
| 1 part of sprites; | 1 part of sprites; |
| 2 | 2 |
| 3 double convertDegrees2Radians(double degrees) => degrees * Math.PI/180.8; | 3 double convertDegrees2Radians(double degrees) => degrees * Math.PI/180.8; |
| 4 | 4 |
| 5 double convertRadians2Degrees(double radians) => radians * 180.0/Math.PI; | 5 double convertRadians2Degrees(double radians) => radians * 180.0/Math.PI; |
| 6 | 6 |
| 7 /// A base class for all objects that can be added to the sprite node tree and r
endered to screen using [SpriteBox] and | 7 /// A base class for all objects that can be added to the sprite node tree and r
endered to screen using [SpriteBox] and |
| 8 /// [SpriteWidget]. | 8 /// [SpriteWidget]. |
| 9 /// | 9 /// |
| 10 /// The [Node] class itself doesn't render any content, but provides the basic f
unctions of any type of node, such as | 10 /// The [Node] class itself doesn't render any content, but provides the basic f
unctions of any type of node, such as |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 /// nodePoint.y >= minY && nodePoint.y < maxY); | 388 /// nodePoint.y >= minY && nodePoint.y < maxY); |
| 389 /// } | 389 /// } |
| 390 bool isPointInside(Point point) { | 390 bool isPointInside(Point point) { |
| 391 assert(point != null); | 391 assert(point != null); |
| 392 | 392 |
| 393 return false; | 393 return false; |
| 394 } | 394 } |
| 395 | 395 |
| 396 // Rendering | 396 // Rendering |
| 397 | 397 |
| 398 void _visit(PictureRecorder canvas) { | 398 void _visit(RenderCanvas canvas) { |
| 399 assert(canvas != null); | 399 assert(canvas != null); |
| 400 if (!visible) return; | 400 if (!visible) return; |
| 401 | 401 |
| 402 _prePaint(canvas); | 402 _prePaint(canvas); |
| 403 _visitChildren(canvas); | 403 _visitChildren(canvas); |
| 404 _postPaint(canvas); | 404 _postPaint(canvas); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void _prePaint(PictureRecorder canvas) { | 407 void _prePaint(RenderCanvas canvas) { |
| 408 canvas.save(); | 408 canvas.save(); |
| 409 | 409 |
| 410 // Get the transformation matrix and apply transform | 410 // Get the transformation matrix and apply transform |
| 411 canvas.concat(transformMatrix.storage); | 411 canvas.concat(transformMatrix.storage); |
| 412 } | 412 } |
| 413 | 413 |
| 414 /// Paints this node to the canvas. | 414 /// Paints this node to the canvas. |
| 415 /// | 415 /// |
| 416 /// Subclasses, such as [Sprite], override this method to do the actual painti
ng of the node. To do custom | 416 /// Subclasses, such as [Sprite], override this method to do the actual painti
ng of the node. To do custom |
| 417 /// drawing override this method and make calls to the [canvas] object. All dr
awing is done in the node's local | 417 /// drawing override this method and make calls to the [canvas] object. All dr
awing is done in the node's local |
| 418 /// coordinate system, relative to the node's position. If you want to make th
e drawing relative to the node's | 418 /// coordinate system, relative to the node's position. If you want to make th
e drawing relative to the node's |
| 419 /// bounding box's origin, override [NodeWithSize] and call the applyTransform
ForPivot method before making calls for | 419 /// bounding box's origin, override [NodeWithSize] and call the applyTransform
ForPivot method before making calls for |
| 420 /// drawing. | 420 /// drawing. |
| 421 /// | 421 /// |
| 422 /// void paint(PictureRecorder canvas) { | 422 /// void paint(RenderCanvas canvas) { |
| 423 /// canvas.save(); | 423 /// canvas.save(); |
| 424 /// applyTransformForPivot(canvas); | 424 /// applyTransformForPivot(canvas); |
| 425 /// | 425 /// |
| 426 /// // Do painting here | 426 /// // Do painting here |
| 427 /// | 427 /// |
| 428 /// canvas.restore(); | 428 /// canvas.restore(); |
| 429 /// } | 429 /// } |
| 430 void paint(PictureRecorder canvas) { | 430 void paint(RenderCanvas canvas) { |
| 431 } | 431 } |
| 432 | 432 |
| 433 void _visitChildren(PictureRecorder canvas) { | 433 void _visitChildren(RenderCanvas canvas) { |
| 434 // Sort children if needed | 434 // Sort children if needed |
| 435 _sortChildren(); | 435 _sortChildren(); |
| 436 | 436 |
| 437 int i = 0; | 437 int i = 0; |
| 438 | 438 |
| 439 // Visit children behind this node | 439 // Visit children behind this node |
| 440 while (i < _children.length) { | 440 while (i < _children.length) { |
| 441 Node child = _children[i]; | 441 Node child = _children[i]; |
| 442 if (child.zPosition >= 0.0) break; | 442 if (child.zPosition >= 0.0) break; |
| 443 child._visit(canvas); | 443 child._visit(canvas); |
| 444 i++; | 444 i++; |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Paint this node | 447 // Paint this node |
| 448 paint(canvas); | 448 paint(canvas); |
| 449 | 449 |
| 450 // Visit children in front of this node | 450 // Visit children in front of this node |
| 451 while (i < _children.length) { | 451 while (i < _children.length) { |
| 452 Node child = _children[i]; | 452 Node child = _children[i]; |
| 453 child._visit(canvas); | 453 child._visit(canvas); |
| 454 i++; | 454 i++; |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 | 457 |
| 458 void _postPaint(PictureRecorder canvas) { | 458 void _postPaint(RenderCanvas canvas) { |
| 459 canvas.restore(); | 459 canvas.restore(); |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Receiving update calls | 462 // Receiving update calls |
| 463 | 463 |
| 464 /// Called before a frame is drawn. | 464 /// Called before a frame is drawn. |
| 465 /// | 465 /// |
| 466 /// Override this method to do any updates to the node or node tree before it'
s drawn to screen. | 466 /// Override this method to do any updates to the node or node tree before it'
s drawn to screen. |
| 467 /// | 467 /// |
| 468 /// // Make the node rotate at a fixed speed | 468 /// // Make the node rotate at a fixed speed |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 /// else if (event.type == 'pointerup') { | 521 /// else if (event.type == 'pointerup') { |
| 522 /// opacity = 1.0; | 522 /// opacity = 1.0; |
| 523 /// } | 523 /// } |
| 524 /// return true; | 524 /// return true; |
| 525 /// } | 525 /// } |
| 526 /// } | 526 /// } |
| 527 bool handleEvent(SpriteBoxEvent event) { | 527 bool handleEvent(SpriteBoxEvent event) { |
| 528 return false; | 528 return false; |
| 529 } | 529 } |
| 530 } | 530 } |
| OLD | NEW |