查看: 5183|回复: 1

[原创发布] 事件使用:高斯模糊(毛玻璃)效果简单实现

[复制链接]
梦石
0
星屑
502
在线时间
909 小时
注册时间
2009-10-12
回帖
1702
发表于 2016-3-21 13:23:39 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 日月星辰 于 2016-3-21 13:26 编辑

自己在制作时候正好用上。请教过别人,然后我自己把功能扩充了下。具体功能可见代码help
另外,由于保存图片在”事件“中,想要渐变,移动等功能只要使用 移动图片 即可实现。

  1. /*:
  2. * @author 日月星辰
  3. * @plugindesc 屏幕截图&模糊 工具
  4. * @help
  5. * 1. 在事件中显示名为 snap 的图片即可获取全屏截图 (可随便放一张图片,推荐为空)
  6. * 2. 在事件中显示名为 blur 的图片即可获取全屏截图并模糊 (同上)
  7. * 3. 在事件中使用插件指令: blurPart x, y, w, h, opacity, id,
  8. *    即可获取区域截图并模糊,保存至id号图片
  9. *
  10. * @param blurLevel
  11. * @desc 模糊的等级,越高越糊,推荐范围[1,5],默认1
  12. * @default 1
  13. */

  14. var params = PluginManager.parameters('SnapBlur');

  15. var blurLevel = Number(params['blurLevel'] || 1);

  16. var x;
  17. var y;
  18. var w;
  19. var h;

  20. (function() {
  21. Sprite_Picture.prototype.loadBitmap = function() {
  22.   if (this._pictureName === "snap") {
  23.     this.bitmap = SceneManager.snap();
  24.   } else if (this._pictureName === "blur" ){
  25.     this.bitmap = SceneManager.snap();
  26.     for (var i = 0; i < blurLevel; i++)
  27.       this.bitmap.blur();
  28.   } else if (this._pictureName === "blurPart") {
  29.     this.bitmap = SceneManager.snap();
  30.     for (var i = 0; i < blurLevel; i++)
  31.       this.bitmap.blurArea(x, y, w, h);
  32.   } else {
  33.     this.bitmap = ImageManager.loadPicture(this._pictureName);
  34.   }
  35. };
  36. })();

  37. var alias_command = Game_Interpreter.prototype.pluginCommand;
  38. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  39.   alias_command.call(this, command, args);
  40.   if (command === 'blurPart') {
  41.     x = parseInt(args[0]);
  42.     y = parseInt(args[1]);
  43.     w = parseInt(args[2]);
  44.     h = parseInt(args[3]);

  45.     var opacity = parseInt(args[4]);
  46.     var id = parseInt(args[5]);

  47.     $gameScreen.showPicture(id, "blurPart" ,0, 0, 0, 100, 100, opacity, 0, x, w, y, h);
  48.   }
  49.   return true;
  50. };

  51. Bitmap.prototype.blurArea = function(x, y, w, h) {
  52.     for (var i = 0; i < 2; i++) {
  53.         var canvas = this._canvas;
  54.         var context = this._context;
  55.         var tempCanvas = document.createElement('canvas');
  56.         var tempContext = tempCanvas.getContext('2d');
  57.         tempCanvas.width = w + 2;
  58.         tempCanvas.height = h + 2;
  59.         tempContext.drawImage(canvas, x, y, w, h, 1, 1, w, h);
  60.         tempContext.drawImage(canvas, x, y, w, 1, 1, 0, w, 1);
  61.         tempContext.drawImage(canvas, x, y, 1, h, 0, 1, 1, h);
  62.         tempContext.drawImage(canvas, x, h - 1, w, 1, 1, h + 1, w, 1);
  63.         tempContext.drawImage(canvas, w - 1, y, 1, h, w + 1, 1, 1, h);
  64.         context.save();
  65.         context.fillStyle = 'black';
  66.         context.fillRect(x, y, w, h);
  67.         context.globalCompositeOperation = 'lighter';
  68.         context.globalAlpha = 1 / 9;
  69.         for (var yy = 0; yy < 3; yy++) {
  70.             for (var xx = 0; xx < 3; xx++) {
  71.                 context.drawImage(tempCanvas, xx, yy, w, h, x, y, w, h);
  72.             }
  73.         }
  74.         context.restore();
  75.     }
  76.     this._setDirty();
  77. };
复制代码

梦石
0
星屑
1622
在线时间
719 小时
注册时间
2013-10-20
回帖
121

开拓者

发表于 2016-3-21 21:37:49 | 显示全部楼层
有效果图吗?
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部