设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 146|回复: 3
打印 上一主题 下一主题

[有事请教] 目的地光标

[复制链接]

Lv2.观梦者

故九江太守

梦石
0
星屑
554
在线时间
2159 小时
注册时间
2012-12-5
帖子
4463
跳转到指定楼层
1
发表于 2024-9-4 03:50:58 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
RUBY 代码复制
  1. /*:
  2. * @target MZ
  3. * @author sun
  4. * @plugindesc 地图目的地光标
  5. * @help
  6. * 好像没啥好说的
  7. *
  8. * @param Img
  9. * @text 资源
  10. * @type file
  11. * @require 1
  12. * @dir img/system
  13. * @desc 序列帧图像素材
  14. * @default cursor
  15. *
  16. * @param Number Of Frames
  17. * @text 图片帧数
  18. * @type number
  19. * @min 0
  20. * @default 4
  21. * @desc 所用的序列帧动画图像的帧数
  22. *
  23. * @param Animation Speed
  24. * @text 动画速度
  25. * @type number
  26. * @min 0
  27. * @default 6
  28. * @desc 序列帧动画间隔多少帧播放下一帧
  29. */
  30.  
  31. var Imported = Imported || {};
  32. Imported.sun_MapCursor = true;
  33.  
  34. (() => {
  35.     const sun_MapCursor = {};
  36.     sun_MapCursor.parameters = PluginManager.parameters("sun_MapCursor");
  37.     sun_MapCursor.fileName = String(sun_MapCursor.parameters["Img"]);
  38.     sun_MapCursor.framesNum = Number(sun_MapCursor.parameters["Number Of Frames"] || 0);
  39.     sun_MapCursor.speed = Number(sun_MapCursor.parameters["Animation Speed"] || 0);
  40.  
  41.  
  42.     Sprite_Destination.prototype.initialize = function () {
  43.         Sprite.prototype.initialize.call(this);
  44.         this.createBitmap();
  45.         this._frameCount = 0;
  46.         this._index = 0;
  47.     }
  48.  
  49.     Sprite_Destination.prototype.createBitmap = function () {
  50.         const { fileName } = sun_MapCursor;
  51.         this.bitmap = ImageManager.loadSystem(fileName);
  52.         this.anchor.x = 0.5;
  53.         this.anchor.y = 0.5;
  54.     }
  55.  
  56.     Sprite_Destination.prototype.updateAnimation = function () {
  57.         const { framesNum, speed } = sun_MapCursor;
  58.         const bitmap = this.bitmap;
  59.         const index = Math.floor(this._frameCount / speed) % framesNum;
  60.         const w = bitmap.width / framesNum;
  61.         const h = bitmap.height;
  62.         const x = w * index;
  63.         const y = 0;
  64.         this.setFrame(x, y, w, h);
  65.         this._frameCount++;
  66.     }
  67. })()

切换场景的时候就失效了是为什么?

Lv2.观梦者

故九江太守

梦石
0
星屑
554
在线时间
2159 小时
注册时间
2012-12-5
帖子
4463
3
 楼主| 发表于 2024-9-11 00:01:53 | 只看该作者
sundeshuo 发表于 2024-9-4 11:45
光标精灵销毁的时候会销毁位图,然后system的图片会进缓存,ImageManager.loadSystem读取位图的时候因为缓 ...
  1. // 重写 destroy 方法
  2.     const originalDestroy = Sprite_Destination.prototype.destroy;
  3.     Sprite_Destination.prototype.destroy = function() {
  4.         // 不销毁 bitmap,只进行其他清理操作
  5.         this._frameCount = 0;
  6.         this._index = 0;
  7.         // 调用原始的 destroy 方法(如果有其他需要清理的操作)
  8.         originalDestroy.call(this);
  9.     };
复制代码

两种方法我都试了,切换场景还是会失效呀
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
4829
在线时间
401 小时
注册时间
2012-2-19
帖子
50
2
发表于 2024-9-4 11:45:18 | 只看该作者
光标精灵销毁的时候会销毁位图,然后system的图片会进缓存,ImageManager.loadSystem读取位图的时候因为缓存中存在不会重新加载,但是这个位图已经被销毁了,所以切图就失效了
改一下光标精灵的destroy方法,或者51行的ImageManager.loadSystem改成ImageManager.loadPicture然后图片放到pictures文件夹里

点评

可以了哈哈,又调用了原方法  发表于 2024-9-11 00:02
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-21 11:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表