[improve] PartView shadow

This commit is contained in:
2020-01-29 18:01:35 +03:00
parent 3aa6b27a52
commit f1cf629d38
4 changed files with 25 additions and 11 deletions

View File

@@ -72,8 +72,9 @@ class GameUtil {
height = normilizeSize(height); height = normilizeSize(height);
var offsetX = 500; var offsetX = 500;
var offsetY = 200; var offsetY = 200;
var imageSize = 1024;
var s = width / height; var s = width / height;
var imageRect = new Rectangle(offsetX, offsetY, 1024, 1024 / s); var imageRect = new Rectangle(offsetX, offsetY, imageSize, imageSize / s);
var tableRect = new Rectangle(0, 0, imageRect.width + offsetX * 2, imageRect.height + offsetY * 2); var tableRect = new Rectangle(0, 0, imageRect.width + offsetX * 2, imageRect.height + offsetY * 2);
return { return {
image:image, image:image,

View File

@@ -31,7 +31,9 @@ class PartView extends Sprite {
public function new(id:Int, image:BitmapData, size:Point) { public function new(id:Int, image:BitmapData, size:Point) {
super(); super();
#if !android
filters = RenderUtil.buildFilters(); filters = RenderUtil.buildFilters();
#end
this.id = id; this.id = id;
this.size = size; this.size = size;
if (image != null) { if (image != null) {
@@ -51,7 +53,7 @@ class PartView extends Sprite {
} }
public static function factory(id:Int, image:BitmapData, size:Point):PartView { public static function factory(id:Int, image:BitmapData, size:Point):PartView {
return new BitmapPartView(id, image, size); return new SpritePartView(id, image, size);
} }
} }

View File

@@ -1,5 +1,7 @@
package ru.m.puzzlez.render; package ru.m.puzzlez.render;
import flash.geom.Point;
import ru.m.puzzlez.render.mask.IPartMaskBuilder.DrawPath;
import flash.display.BitmapData; import flash.display.BitmapData;
import flash.display.Shape; import flash.display.Shape;
import flash.filters.BitmapFilter; import flash.filters.BitmapFilter;
@@ -39,13 +41,16 @@ class RenderUtil {
var canvas:Shape = new Shape(); var canvas:Shape = new Shape();
canvas.cacheAsBitmap = true; canvas.cacheAsBitmap = true;
canvas.mask = mask; canvas.mask = mask;
canvas.graphics.beginBitmapFill(source, null, false, true);
canvas.graphics.drawRect(0, 0, source.width, source.height);
canvas.graphics.endFill();
var image = new BitmapData(Std.int(mask.rect.width), Std.int(mask.rect.height), true, 0x00000000);
var matrix = new Matrix(); var matrix = new Matrix();
matrix.translate(-mask.rect.x, -mask.rect.y); matrix.translate(-mask.rect.x, -mask.rect.y);
image.draw(canvas, matrix, null, null, null, true); canvas.graphics.beginBitmapFill(source, matrix, false, true);
canvas.graphics.drawRect(0, 0, mask.rect.width, mask.rect.height);
canvas.graphics.endFill();
var image = new BitmapData(Std.int(mask.rect.width), Std.int(mask.rect.height), true, 0x00000000);
image.draw(canvas, null, null, null, null, true);
/*for (filter in buildFilters()) {
image.applyFilter(image, image.rect, image.rect.topLeft, filter);
}*/
return image; return image;
} }

View File

@@ -3,22 +3,28 @@ package ru.m.puzzlez.render.mask;
import flash.display.Shape; import flash.display.Shape;
import flash.geom.Rectangle; import flash.geom.Rectangle;
import ru.m.puzzlez.core.Part; import ru.m.puzzlez.core.Part;
import ru.m.puzzlez.render.mask.IPartMaskBuilder;
class PartMask extends Shape { class PartMask extends Shape {
public var rect(default, null):Rectangle; public var rect(default, null):Rectangle;
private static var builder:IPartMaskBuilder = new ClassicMaskBuilder();
public function new(rect:Rectangle, bounds:Bounds) { public function new(rect:Rectangle, bounds:Bounds) {
super(); super();
graphics.beginFill(0xff00ff, 1);
var path = new ClassicMaskBuilder().build(rect, bounds);
graphics.drawPath(path.commands, path.data);
graphics.endFill();
this.rect = rect.clone(); this.rect = rect.clone();
var offset = rect.width / 4 + rect.width * 0.05; var offset = rect.width / 4 + rect.width * 0.05;
this.rect.x -= offset; this.rect.x -= offset;
this.rect.y -= offset; this.rect.y -= offset;
this.rect.width += offset * 2; this.rect.width += offset * 2;
this.rect.height += offset * 2; this.rect.height += offset * 2;
var drawRect = rect.clone();
drawRect.x = offset;
drawRect.y = offset;
var drawPath = builder.build(drawRect, bounds);
graphics.beginFill(0xff00ff, 1);
graphics.drawPath(drawPath.commands, drawPath.data);
graphics.endFill();
} }
} }