| 赞 | 150 |
| VIP | |
| 好人卡 | |
| 积分 | 314 |
| 经验 | |
| 最后登录 | 2026-9-21 |
| 在线时间 | 1525 小时 |
- 梦石
- 18
- 星屑
- 13373
- 在线时间
- 1525 小时
- 注册时间
- 2020-3-21
- 回帖
- 334
 
|
发表于 2022-2-8 13:35:21
|
显示全部楼层
_blendColor这个东西吧……的确最好不要用。
当你每设置一次_blendColor时,都会执行sprite的_refresh函数(1.6.2版的rpg_core.js第4179行)。
在_refresh函数中会执行_executeTint函数(1.6.2版的rpg_core.js第4277行)。
这个函数是这样:
[pre lang="javascript"]Sprite.prototype._executeTint = function(x, y, w, h) {
var context = this._context;
var tone = this._colorTone;
var color = this._blendColor;
context.globalCompositeOperation = 'copy';
context.drawImage(this._bitmap.canvas, x, y, w, h, 0, 0, w, h);
if (Graphics.canUseSaturationBlend()) {
var gray = Math.max(0, tone[3]);
context.globalCompositeOperation = 'saturation';
context.fillStyle = 'rgba(255,255,255,' + gray / 255 + ')';
context.fillRect(0, 0, w, h);
}
var r1 = Math.max(0, tone[0]);
var g1 = Math.max(0, tone[1]);
var b1 = Math.max(0, tone[2]);
context.globalCompositeOperation = 'lighter';
context.fillStyle = Utils.rgbToCssColor(r1, g1, b1);
context.fillRect(0, 0, w, h);
if (Graphics.canUseDifferenceBlend()) {
context.globalCompositeOperation = 'difference';
context.fillStyle = 'white';
context.fillRect(0, 0, w, h);
var r2 = Math.max(0, -tone[0]);
var g2 = Math.max(0, -tone[1]);
var b2 = Math.max(0, -tone[2]);
context.globalCompositeOperation = 'lighter';
context.fillStyle = Utils.rgbToCssColor(r2, g2, b2);
context.fillRect(0, 0, w, h);
context.globalCompositeOperation = 'difference';
context.fillStyle = 'white';
context.fillRect(0, 0, w, h);
}
var r3 = Math.max(0, color[0]);
var g3 = Math.max(0, color[1]);
var b3 = Math.max(0, color[2]);
var a3 = Math.max(0, color[3]);
context.globalCompositeOperation = 'source-atop';
context.fillStyle = Utils.rgbToCssColor(r3, g3, b3);
context.globalAlpha = a3 / 255;
context.fillRect(0, 0, w, h);
context.globalCompositeOperation = 'destination-in';
context.globalAlpha = 1;
context.drawImage(this._bitmap.canvas, x, y, w, h, 0, 0, w, h);
};[/pre]
如果是单纯设置一次sprite的_blendColor,之后不每帧都设置,那还好说,但是一直设置的话就会一直执行_refresh,一直执行_executeTint,就会掉帧。
修改sprite的其他属性,例如bitmap,frame等,也会执行_refresh……
根据你具体想实现的效果来想解决办法。 |
评分
-
查看全部评分
|