Skip to content

Commit ab93f3c

Browse files
authored
Merge pull request rpgtkoolmv#152 from rpgtkoolmv/improve_flash
Flashing sprites faster
2 parents 96ca878 + 95485a6 commit ab93f3c

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

js/rpg_core/Sprite.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -346,35 +346,37 @@ Sprite.prototype._executeTint = function(x, y, w, h) {
346346
context.globalCompositeOperation = 'copy';
347347
context.drawImage(this._bitmap.canvas, x, y, w, h, 0, 0, w, h);
348348

349-
if (Graphics.canUseSaturationBlend()) {
350-
var gray = Math.max(0, tone[3]);
351-
context.globalCompositeOperation = 'saturation';
352-
context.fillStyle = 'rgba(255,255,255,' + gray / 255 + ')';
353-
context.fillRect(0, 0, w, h);
354-
}
355-
356-
var r1 = Math.max(0, tone[0]);
357-
var g1 = Math.max(0, tone[1]);
358-
var b1 = Math.max(0, tone[2]);
359-
context.globalCompositeOperation = 'lighter';
360-
context.fillStyle = Utils.rgbToCssColor(r1, g1, b1);
361-
context.fillRect(0, 0, w, h);
362-
363-
if (Graphics.canUseDifferenceBlend()) {
364-
context.globalCompositeOperation = 'difference';
365-
context.fillStyle = 'white';
366-
context.fillRect(0, 0, w, h);
349+
if (tone[0] || tone[1] || tone[2] || tone[3]) {
350+
if (Graphics.canUseSaturationBlend()) {
351+
var gray = Math.max(0, tone[3]);
352+
context.globalCompositeOperation = 'saturation';
353+
context.fillStyle = 'rgba(255,255,255,' + gray / 255 + ')';
354+
context.fillRect(0, 0, w, h);
355+
}
367356

368-
var r2 = Math.max(0, -tone[0]);
369-
var g2 = Math.max(0, -tone[1]);
370-
var b2 = Math.max(0, -tone[2]);
357+
var r1 = Math.max(0, tone[0]);
358+
var g1 = Math.max(0, tone[1]);
359+
var b1 = Math.max(0, tone[2]);
371360
context.globalCompositeOperation = 'lighter';
372-
context.fillStyle = Utils.rgbToCssColor(r2, g2, b2);
361+
context.fillStyle = Utils.rgbToCssColor(r1, g1, b1);
373362
context.fillRect(0, 0, w, h);
374363

375-
context.globalCompositeOperation = 'difference';
376-
context.fillStyle = 'white';
377-
context.fillRect(0, 0, w, h);
364+
if (Graphics.canUseDifferenceBlend()) {
365+
context.globalCompositeOperation = 'difference';
366+
context.fillStyle = 'white';
367+
context.fillRect(0, 0, w, h);
368+
369+
var r2 = Math.max(0, -tone[0]);
370+
var g2 = Math.max(0, -tone[1]);
371+
var b2 = Math.max(0, -tone[2]);
372+
context.globalCompositeOperation = 'lighter';
373+
context.fillStyle = Utils.rgbToCssColor(r2, g2, b2);
374+
context.fillRect(0, 0, w, h);
375+
376+
context.globalCompositeOperation = 'difference';
377+
context.fillStyle = 'white';
378+
context.fillRect(0, 0, w, h);
379+
}
378380
}
379381

380382
var r3 = Math.max(0, color[0]);

0 commit comments

Comments
 (0)