设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 153|回复: 0

[转载发布] Destination Sprite

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9072

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58885
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68851

    灌水之王

    发表于 2026-7-30 15:36:07 | 显示全部楼层 |阅读模式

    Destination Sprite



    By Krimer


    Introduction


       Customizable destination sprite for mouse/touch input


    Features
        - Easy to use.
        - Resize and recolor the destination sprite
        - Use a custom image or spritesheet as the destination sprite
        - Multiple animation modes


    Screenshots







    How to Use


    • Create file with name DestinationSprite.js
    • add file to /plugin folder of your project
    • Activate DestinationSprite in plugin manager

    Plugin MV-MZ

    Spoiler                JavaScript:       
    1. //=============================================================================
    2. // DestinationSprite.js
    3. // Version: v2.0.5
    4. //=============================================================================
    5. /*:
    6. * @target MZ
    7. * @plugindesc <DestinationSprite> v2.0.5 - Customizable destination sprite for mouse/touch input with spritesheet animation support
    8. *
    9. * @author Krimer
    10. *
    11. * @param spriteType
    12. * @text Sprite type
    13. * @type select
    14. * @option Square
    15. * @option Circle
    16. * @option Custom
    17. * @option Spritesheet
    18. * @option Off
    19. * @default Square
    20. * @desc Type of destination sprite to display
    21. *
    22. * @param imageName
    23. * @text Image name
    24. * @type file
    25. * @dir img/system
    26. * @default
    27. * @desc Image file for Custom or Spritesheet types (from img/system/)
    28. *
    29. * @param Sprite Settings
    30. * @default
    31. *
    32. * @param spriteSize
    33. * @text Sprite size
    34. * @parent Sprite Settings
    35. * @type number
    36. * @min 1
    37. * @default 48
    38. * @desc Size in pixels for Square/Circle types. Default: 48
    39. *
    40. * @param spriteColor
    41. * @text Sprite color
    42. * @parent Sprite Settings
    43. * @type text
    44. * @default #ffffff
    45. * @desc Color for Square/Circle types (hex format). Default: #ffffff
    46. *
    47. * @param spriteOpacity
    48. * @text Sprite opacity
    49. * @parent Sprite Settings
    50. * @type number
    51. * @min 0
    52. * @max 255
    53. * @default 120
    54. * @desc Maximum opacity (0-255). Default: 120
    55. *
    56. * @param blendMode
    57. * @text Blend mode
    58. * @parent Sprite Settings
    59. * @type select
    60. * @option Normal
    61. * @option Additive
    62. * @default Additive
    63. * @desc Blend mode for the sprite. Default: Additive
    64. *
    65. * @param Animation Settings
    66. * @default
    67. *
    68. * @param animationMode
    69. * @text Animation mode
    70. * @parent Animation Settings
    71. * @type select
    72. * @option Loop
    73. * @option Once
    74. * @default Loop
    75. * @desc Loop = continuous animation, Once = play once then fade out
    76. *
    77. * @param fadeSpeed
    78. * @text Fade speed
    79. * @parent Animation Settings
    80. * @type number
    81. * @min 1
    82. * @max 50
    83. * @default 12
    84. * @desc Opacity decrease per frame for "Once" mode. Default: 12
    85. *
    86. * @param scaleAnimation
    87. * @text Scale animation
    88. * @parent Animation Settings
    89. * @type boolean
    90. * @default true
    91. * @desc Enable pulsing scale effect for Loop mode (Square/Circle/Custom only)
    92. *
    93. * @param Spritesheet Settings
    94. * @default
    95. *
    96. * @param frameWidth
    97. * @text Frame width
    98. * @parent Spritesheet Settings
    99. * @type number
    100. * @min 1
    101. * @default 48
    102. * @desc Width of each frame for Spritesheet type. Default: 48
    103. *
    104. * @param frameHeight
    105. * @text Frame height
    106. * @parent Spritesheet Settings
    107. * @type number
    108. * @min 1
    109. * @default 48
    110. * @desc Height of each frame for Spritesheet type. Default: 48
    111. *
    112. * @param frameNumber
    113. * @text Number of frames
    114. * @parent Spritesheet Settings
    115. * @type number
    116. * @min 1
    117. * @default 8
    118. * @desc Number of frames in the spritesheet. Default: 8
    119. *
    120. * @param animationSpeed
    121. * @text Animation speed
    122. * @parent Spritesheet Settings
    123. * @type number
    124. * @min 1
    125. * @max 60
    126. * @default 6
    127. * @desc Frames to wait between animation updates. Lower = faster. Default: 6
    128. *
    129. * @param loopType
    130. * @text Loop type
    131. * @parent Spritesheet Settings
    132. * @type select
    133. * @option Forward
    134. * @option Ping-Pong
    135. * @default Forward
    136. * @desc Forward = 1,2,3,1,2,3... Ping-Pong = 1,2,3,2,1,2,3...
    137. *
    138. * @help
    139. * Compatible with both RPG Maker MV and MZ
    140. *
    141. * SPRITE TYPES
    142. * -Square: Simple filled square
    143. * -Circle: Simple filled circle
    144. * -Custom: Single custom image from img/system/
    145. * -Spritesheet: Animated spritesheet (horizontal strip) from img/system/
    146. * -Off: Hide the destination sprite completely
    147. *
    148. * ANIMATION MODES
    149. * -Loop: Continuous animation (spritesheet loops, shapes pulse)
    150. * -Once: Play animation once then fade out
    151. * For Spritesheet type:
    152. * -Loop mode: Frames play continuously (Forward or Ping-Pong)
    153. * -Once mode: Frames play once then sprite fades out
    154. *
    155. * SPRITESHEET FORMAT
    156. * Spritesheets should be horizontal strips with all frames in a single row
    157. * Example: 8 frames at 48x48 = 384x48 pixel image
    158. *
    159. * Enable/Disable sprite script call:
    160. *   $gameTemp.setDestinationSpriteEnabled(true);
    161. *   $gameTemp.setDestinationSpriteEnabled(false);
    162. *
    163. * You can find the color picker here, or use any graphic editor that works with hex color codes
    164. * https://www.w3schools.com/colors/colors_picker.asp
    165. */
    166. //=============================================================================
    167. var Imported = Imported || {};
    168. Imported.Krimer_DestinationSprite = true;
    169. (function() {
    170.     const parameters = $plugins.filter(function(p) { return p.description.contains('<DestinationSprite>'); })[0].parameters;
    171.     const dSpriteType = String(parameters['spriteType'] || 'Square');
    172.     const dImageName = String(parameters['imageName'] || '');
    173.     const dSpriteSize = Number(parameters['spriteSize'] || 48);
    174.     const dSpriteColor = String(parameters['spriteColor'] || '#ffffff');
    175.     const dSpriteOpacity = Number(parameters['spriteOpacity'] || 120);
    176.     const dBlendMode = parameters['blendMode'] == 'Additive' ? 1 : 0;
    177.     const dAnimationMode = String(parameters['animationMode'] || 'Loop');
    178.     const dFadeSpeed = Number(parameters['fadeSpeed'] || 12);
    179.     const dScaleAnimation = parameters['scaleAnimation'] != 'false';
    180.     const dFrameWidth = Number(parameters['frameWidth'] || 48);
    181.     const dFrameHeight = Number(parameters['frameHeight'] || 48);
    182.     const dFrameNumber = Number(parameters['frameNumber'] || 8);
    183.     const dAnimSpeed = Number(parameters['animationSpeed'] || 6);
    184.     const dLoopType = String(parameters['loopType'] || 'Forward');
    185.     const Game_Temp_initialize_dAlias = Game_Temp.prototype.initialize;
    186.     Game_Temp.prototype.initialize = function() {
    187.         Game_Temp_initialize_dAlias.call(this);
    188.         this._destinationOpacity = 0;
    189.         this._destinationSpriteEnabled = true;
    190.     };
    191.     Game_Temp.prototype.setDestinationOpacity = function(value) {
    192.         this._destinationOpacity = value;
    193.     };
    194.     Game_Temp.prototype.getDestinationOpacity = function() {
    195.         return this._destinationOpacity;
    196.     };
    197.     Game_Temp.prototype.setDestinationSpriteEnabled = function(value) {
    198.         this._destinationSpriteEnabled = value;
    199.     };
    200.     Game_Temp.prototype.isDestinationSpriteEnabled = function() {
    201.         return this._destinationSpriteEnabled;
    202.     };
    203.     const Game_Temp_setDestination_dAlias = Game_Temp.prototype.setDestination;
    204.     Game_Temp.prototype.setDestination = function(x, y) {
    205.         if (dAnimationMode == "Once" && (this._destinationX !== x || this._destinationY != y)) {
    206.             this._destinationOpacity = dSpriteOpacity;
    207.         }
    208.         Game_Temp_setDestination_dAlias.call(this, x, y);
    209.     };
    210.   
    211.     const Sprite_Destination_initialize_dAlias = Sprite_Destination.prototype.initialize;
    212.     Sprite_Destination.prototype.initialize = function() {
    213.         this._currentType = null;
    214.         this._bitmapReady = false;
    215.         this._animFrame = 0;
    216.         this._animDir = 1;
    217.         this._animTimer = 0;
    218.         Sprite_Destination_initialize_dAlias.call(this);
    219.         this.opacity = 0;
    220.     };
    221.     Sprite_Destination.prototype.destroy = function(options) {
    222.         if (this._currentType == 'Custom' || this._currentType == 'Spritesheet') {
    223.             options = { children: false, texture: false, baseTexture: false };
    224.         }
    225.         Sprite.prototype.destroy.call(this, options);
    226.     };
    227.     Sprite_Destination.prototype.createBitmap = function() {
    228.         var tileWidth = dSpriteSize || $gameMap.tileWidth();
    229.         var tileHeight = dSpriteSize || $gameMap.tileHeight();
    230.         this._currentType = dSpriteType;
    231.         this._bitmapReady = false;
    232.         this._animFrame = 0;
    233.         this._animDir = 1;
    234.         this._animTimer = 0;
    235.         this.bitmap = new Bitmap(tileWidth, tileHeight);
    236.         if (dSpriteType == 'Square') {
    237.             this.bitmap.fillAll(dSpriteColor);
    238.             this._bitmapReady = true;
    239.         } else if (dSpriteType == 'Circle') {
    240.             this.bitmap.drawCircle(this.bitmap.width / 2, this.bitmap.height / 2, dSpriteSize / 2, dSpriteColor);
    241.             this._bitmapReady = true;
    242.         } else if (dSpriteType == 'Off') {
    243.             this._bitmapReady = true;
    244.         } else if (dSpriteType == 'Custom') {
    245.             if (dImageName) {
    246.                 var self = this;
    247.                 var bmp = ImageManager.loadSystem(dImageName);
    248.                 if (bmp.isReady()) {
    249.                     this.bitmap = bmp;
    250.                     this._bitmapReady = true;
    251.                 } else {
    252.                     bmp.addLoadListener(function() {
    253.                         self.bitmap = bmp;
    254.                         self._bitmapReady = true;
    255.                     });
    256.                 }
    257.             } else { this._bitmapReady = true; }
    258.         } else if (dSpriteType == 'Spritesheet') {
    259.             if (dImageName) {
    260.                 var self = this;
    261.                 var bmp = ImageManager.loadSystem(dImageName);
    262.                 if (bmp.isReady()) {
    263.                     this.bitmap = bmp;
    264.                     this._bitmapReady = true;
    265.                     this.setFrame(0, 0, dFrameWidth, dFrameHeight);
    266.                 } else {
    267.                     bmp.addLoadListener(function() {
    268.                         self.bitmap = bmp;
    269.                         self._bitmapReady = true;
    270.                         self.setFrame(0, 0, dFrameWidth, dFrameHeight);
    271.                     });
    272.                 }
    273.             } else { this._bitmapReady = true; }
    274.         }
    275.         this.anchor.x = 0.5;
    276.         this.anchor.y = 0.5;
    277.         this.blendMode = dBlendMode;
    278.     };
    279.     Sprite_Destination.prototype.updateSpriteFrame = function() {
    280.         if (!this.bitmap) return;
    281.         this.setFrame(this._animFrame * dFrameWidth, 0, dFrameWidth, dFrameHeight);
    282.     };
    283.     const Sprite_Destination_update_dAlias = Sprite_Destination.prototype.update;
    284.     Sprite_Destination.prototype.update = function() {
    285.         if (this._currentType !== dSpriteType) {
    286.             this.createBitmap();
    287.         }
    288.         Sprite_Destination_update_dAlias.call(this);
    289.     };
    290.     Sprite_Destination.prototype.updateAnimation = function() {
    291.         if (!$gameTemp.isDestinationSpriteEnabled()) {
    292.             this.opacity = 0;
    293.             return;
    294.         }
    295.         if (dSpriteType == 'Off' || !this._bitmapReady) {
    296.             this.opacity = 0;
    297.             return;
    298.         }
    299.         this._frameCount++;
    300.         this._frameCount %= 20;
    301.         if (dSpriteType == 'Spritesheet') {
    302.             this.updateSpritesheetAnim();
    303.         } else {
    304.             this.updateBasicAnim();
    305.         }
    306.     };
    307.     Sprite_Destination.prototype.updateBasicAnim = function() {
    308.         if (dAnimationMode == "Loop") {
    309.             this.opacity = dSpriteOpacity === 255 ? 255 : dSpriteOpacity - Math.abs(10 - this._frameCount) * 6;
    310.             if (dScaleAnimation) {
    311.                 this.scale.x = 1 + this._frameCount / 20;
    312.                 this.scale.y = this.scale.x;
    313.             } else {
    314.                 this.scale.x = this.scale.y = 1;
    315.             }
    316.         } else if (dAnimationMode == "Once" && $gameTemp.getDestinationOpacity() > 0) {
    317.             this.scale.x = this.scale.y = 1;
    318.             this.opacity = $gameTemp.getDestinationOpacity() - dFadeSpeed;
    319.             $gameTemp.setDestinationOpacity(this.opacity);
    320.         } else { this.opacity = 0; }
    321.     };
    322.     Sprite_Destination.prototype.updateSpritesheetAnim = function() {
    323.         this.scale.x = this.scale.y = 1;
    324.         this._animTimer++;
    325.         if (this._animTimer < dAnimSpeed) {
    326.             if (dAnimationMode == "Once" && this._animFrame >= dFrameNumber - 1) {
    327.                 if ($gameTemp.getDestinationOpacity() > 0) {
    328.                     this.opacity = $gameTemp.getDestinationOpacity() - dFadeSpeed;
    329.                     $gameTemp.setDestinationOpacity(this.opacity);
    330.                 } else { this.opacity = 0; }
    331.             }
    332.             return;
    333.         }
    334.         this._animTimer = 0;
    335.         if (dAnimationMode == "Loop") {
    336.             if (dLoopType == 'Ping-Pong') {
    337.                 if (this._animFrame >= dFrameNumber - 1) { this._animDir = -1; }
    338.                 if (this._animFrame <= 0) { this._animDir = 1; }
    339.                 this._animFrame += this._animDir;
    340.             } else {
    341.                 this._animFrame++;
    342.                 if (this._animFrame >= dFrameNumber) this._animFrame = 0;
    343.             }
    344.             this.opacity = dSpriteOpacity;
    345.         } else {
    346.             if (this._animFrame < dFrameNumber - 1) {
    347.                 this._animFrame++;
    348.                 this.opacity = dSpriteOpacity;
    349.             } else if ($gameTemp.getDestinationOpacity() > 0) {
    350.                 this.opacity = $gameTemp.getDestinationOpacity() - dFadeSpeed;
    351.                 $gameTemp.setDestinationOpacity(this.opacity);
    352.             } else { this.opacity = 0; }
    353.         }
    354.         this.updateSpriteFrame();
    355.     };
    356.     const Scene_Map_onMapLoaded_dAlias = Scene_Map.prototype.onMapLoaded;
    357.     Scene_Map.prototype.onMapLoaded = function() {
    358.         Scene_Map_onMapLoaded_dAlias.call(this);
    359.         if (dImageName && (dSpriteType == 'Custom' || dSpriteType == 'Spritesheet')) {
    360.             ImageManager.loadSystem(dImageName);
    361.         }
    362.     };
    363. })();
    复制代码







    Author's Notes


        Free to use. Feel free to use it however you like. If you'd like, you can credit me, but it's not required.  



    本贴来自国际rpgmaker官方论坛作者:Krimer处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/destination-sprite.50602/

    本帖子中包含更多资源

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

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-21 18:13 , Processed in 0.140839 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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