[render] tankz colors

This commit is contained in:
2018-02-08 23:12:10 +03:00
parent dd1014e230
commit a7effef412
26 changed files with 66 additions and 61 deletions

View File

@@ -8,8 +8,9 @@ import flash.display.BitmapData;
class BitmapUtil {
public static function colorize(data: BitmapData, color: Color):BitmapData {
if (color.zero) return data;
var result = data.clone();
var transform = new ColorTransform(1, 1, 1, 1, color.red, color.green, color.blue, color.alpha);
var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0);
result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform);
return result;
}

View File

@@ -5,6 +5,7 @@ abstract Color(Int) {
public var red(get, never):Int;
public var green(get, never):Int;
public var blue(get, never):Int;
public var zero(get, never):Bool;
public inline function new(value:Int) {
this = value;
@@ -26,6 +27,15 @@ abstract Color(Int) {
return this & 255;
}
private inline function get_zero():Bool {
return this == 0;
}
@:from
static public inline function fromInt(value:Int):Color {
return new Color(value);
}
@:from
static public inline function fromString(value:String):Color {
return new Color(Std.parseInt('0x${value.split('#').pop()}'));

View File

@@ -155,32 +155,14 @@ class TankItem extends RenderItem<Tank, Sprite> {
}
override public function redraw():Void {
// ToDo: ImageBundle
tankView.frames = getFrames().map(function(s) return BitmapUtil.colorize(Assets.getBitmapData(s), '#cc0000'));
}
public static function getTankFrames(team:TeamId, index:Int, type:TankType, hits:Int=0):Array<String> {
var group = type.group;
if (team == 'radiant') {
index = 0;
}
if (team == 'dire') {
index = 1;
}
if (team == 'human' || team == 'radiant' || team == 'dire') {
group = 'player';
}
if (team == 'bot') {
index = hits;
}
return [
'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-0.png',
'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-1.png',
];
tankView.frames = getFrames().map(function(src) return BitmapUtil.colorize(Assets.getBitmapData(src), value.color));
}
private function getFrames():Array<String> {
return getTankFrames(value.playerId.team, value.playerId.index, value.config, value.hits);
return [
'resources/image/tank/${value.config.skin}-0.png',
'resources/image/tank/${value.config.skin}-1.png',
];
}
override public function update():Void {