Commit 3b06e1e1 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds support for transfer mode in Paint and SpriteNode classes. Adds support...

Adds support for transfer mode in Paint and SpriteNode classes. Adds support for opacity in sprites, and modifies example game.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1164633004
parent bcf65bd0
......@@ -66,6 +66,8 @@ class GameWorld extends TransformNode {
SpriteNode sprt = new SpriteNode.withImage(_image);
sprt.width = radius*2;
sprt.height = radius*2;
sprt.colorOverlay = new Color(0x33ff0000);
sprt.transferMode = TransferMode.plusMode;
body.userData = sprt;
this.children.add(sprt);
}
......
......@@ -6,6 +6,9 @@ class SpriteNode extends TransformNode {
Image _image;
bool constrainProportions = false;
double _opacity = 1.0;
Color colorOverlay;
TransferMode transferMode;
SpriteNode() {
this.pivot = new Vector2(0.5, 0.5);
......@@ -16,6 +19,13 @@ class SpriteNode extends TransformNode {
_image = image;
}
double get opacity => _opacity;
void set opacity(double opacity) {
assert(opacity >= 0.0 && opacity <= 1.0);
_opacity = opacity;
}
void paint(PictureRecorder canvas) {
if (_image != null && _image.width > 0 && _image.height > 0) {
......@@ -37,7 +47,18 @@ class SpriteNode extends TransformNode {
}
canvas.scale(scaleX, scaleY);
canvas.drawImage(_image, 0.0, 0.0, new Paint()..setARGB(255, 255, 255, 255));
// Setup paint object for opacity and transfer mode
Paint paint = new Paint();
paint.setARGB((255.0*_opacity).toInt(), 255, 255, 255);
if (colorOverlay != null) {
paint.setColorFilter(new ColorFilter(colorOverlay, TransferMode.srcATopMode));
}
if (transferMode != null) {
paint.setTransferMode(transferMode);
}
canvas.drawImage(_image, 0.0, 0.0, paint);
canvas.restore();
}
else {
......
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