查看: 2499|回复: 4

[有事请教] 有大神知道到底发生了啥么

[复制链接]
梦石
0
星屑
196
在线时间
1037 小时
注册时间
2021-3-24
回帖
548

MZ评测员

发表于 2022-2-7 15:28:25 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
Sprite每帧改变_blendColor并_refresh掉帧掉到姥姥家
GIF.gif
我直接懵逼  就一个Sprite刷这个特效能这么卡么
全家活光光~
梦石
18
星屑
13427
在线时间
1526 小时
注册时间
2020-3-21
回帖
334

MZ评测员极短23获奖

发表于 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行)。
这个函数是这样:

  1. Sprite.prototype._executeTint = function(x, y, w, h) {
  2.     var context = this._context;
  3.     var tone = this._colorTone;
  4.     var color = this._blendColor;

  5.     context.globalCompositeOperation = 'copy';
  6.     context.drawImage(this._bitmap.canvas, x, y, w, h, 0, 0, w, h);

  7.     if (Graphics.canUseSaturationBlend()) {
  8.         var gray = Math.max(0, tone[3]);
  9.         context.globalCompositeOperation = 'saturation';
  10.         context.fillStyle = 'rgba(255,255,255,' + gray / 255 + ')';
  11.         context.fillRect(0, 0, w, h);
  12.     }

  13.     var r1 = Math.max(0, tone[0]);
  14.     var g1 = Math.max(0, tone[1]);
  15.     var b1 = Math.max(0, tone[2]);
  16.     context.globalCompositeOperation = 'lighter';
  17.     context.fillStyle = Utils.rgbToCssColor(r1, g1, b1);
  18.     context.fillRect(0, 0, w, h);

  19.     if (Graphics.canUseDifferenceBlend()) {
  20.         context.globalCompositeOperation = 'difference';
  21.         context.fillStyle = 'white';
  22.         context.fillRect(0, 0, w, h);

  23.         var r2 = Math.max(0, -tone[0]);
  24.         var g2 = Math.max(0, -tone[1]);
  25.         var b2 = Math.max(0, -tone[2]);
  26.         context.globalCompositeOperation = 'lighter';
  27.         context.fillStyle = Utils.rgbToCssColor(r2, g2, b2);
  28.         context.fillRect(0, 0, w, h);

  29.         context.globalCompositeOperation = 'difference';
  30.         context.fillStyle = 'white';
  31.         context.fillRect(0, 0, w, h);
  32.     }

  33.     var r3 = Math.max(0, color[0]);
  34.     var g3 = Math.max(0, color[1]);
  35.     var b3 = Math.max(0, color[2]);
  36.     var a3 = Math.max(0, color[3]);
  37.     context.globalCompositeOperation = 'source-atop';
  38.     context.fillStyle = Utils.rgbToCssColor(r3, g3, b3);
  39.     context.globalAlpha = a3 / 255;
  40.     context.fillRect(0, 0, w, h);

  41.     context.globalCompositeOperation = 'destination-in';
  42.     context.globalAlpha = 1;
  43.     context.drawImage(this._bitmap.canvas, x, y, w, h, 0, 0, w, h);
  44. };
复制代码



如果是单纯设置一次sprite的_blendColor,之后不每帧都设置,那还好说,但是一直设置的话就会一直执行_refresh,一直执行_executeTint,就会掉帧。
修改sprite的其他属性,例如bitmap,frame等,也会执行_refresh……

根据你具体想实现的效果来想解决办法。

点评

实际上将精灵组分开比用一整张更好。若有优化需求(有偿)或者想了解一下相关的知识经验(比如sprite)可以联系我(QQ:975866141)(无偿/有偿)  发表于 2022-2-8 15:41
如果你是自己写插件实现立绘的话,那你可以试试别的方法,修改sprite的颜色并不只有_blendColor一个方法。且可以通过优化来防止循环刷新时的掉帧。  发表于 2022-2-8 15:40
我立绘是精灵组 眼睛脸分开的 循环的刷新,现在只能合成一张位图了  发表于 2022-2-8 15:20

评分

参与人数 1赞 +1 收起 理由
RyanYe + 1 认可答案

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部