查看: 2422|回复: 4

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

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

MZ评测员

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

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

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

×
Sprite每帧改变_blendColor并_refresh掉帧掉到姥姥家
GIF.gif
我直接懵逼  就一个Sprite刷这个特效能这么卡么
全家活光光~
梦石
18
星屑
13373
在线时间
1525 小时
注册时间
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行)。
这个函数是这样:

[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……

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

点评

实际上将精灵组分开比用一整张更好。若有优化需求(有偿)或者想了解一下相关的知识经验(比如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.

在本版发帖返回顶部