查看: 3672|回复: 0

[已经过期] 这个显示心情图标的脚本,显示会稍微错位?

[复制链接]
梦石
1
星屑
22113
在线时间
4886 小时
注册时间
2014-12-22
回帖
1509

开拓者

发表于 2021-2-28 04:45:30 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 shencao 于 2021-2-28 04:43 编辑

这个脚本是,心情图标3~7格循环播放,还可以根据距离角色的远近半透明渐变显示。
但是它这个显示心情,当玩家移动和停止的时候,图标会动一下(错位1像素?),有种滞后的感觉。和默认的心情图标比较一下会很明显。
我用新工程测试过和别的脚本没关系,它原本就是会这么错位一下。
有办法修复吗?

脚本↓

  1. =begin
  2.       RGSS3
  3.       
  4.       ★ フキダシアイコン常時再生 ★

  5.       フキダシアイコンを表示し続けるキャラクターを作ります。
  6.       寝ているキャラなどにどうぞ。
  7.       新たな画像ファイルを作って、お店の看板代わりとかもいいかも。

  8.       ● 仕様 ●==========================================================
  9.       横に8分割されたフキダシアイコン画像の内、
  10.       左から 3~7つ目をループ再生します。
  11.       ====================================================================
  12.       
  13.       ● 使い方 ●========================================================
  14.       イベント>自律移動>カスタム>移動ルート>スクリプトに
  15.           @auto_balloon = n
  16.       と記述してください。nはフキダシアイコンのIDです。
  17.       ====================================================================
  18.       
  19.       ver1.00

  20.       Last Update : 2011/12/18
  21.       12/18 : 新規
  22.       
  23.       ろかん   [url]http://kaisou-ryouiki.sakura.ne.jp/[/url]
  24. =end

  25. #===========================================
  26. #   設定箇所
  27. #===========================================
  28. module Rokan
  29. module Auto_Balloon
  30.     # フキダシの半透明化が始まるプレイヤーとの距離
  31.     # 不透明化を行わない場合は"0"を設定してください。
  32.     DBO = 4

  33. end
  34. end
  35. #===========================================
  36. #   ここまで
  37. #===========================================

  38. $rsi ||= {}
  39. $rsi["フキダシアイコン常時再生"] = true

  40. class Game_Event < Game_Character
  41.   #--------------------------------------------------------------------------
  42.   # ● 公開インスタンス変数
  43.   #--------------------------------------------------------------------------
  44.   attr_reader   :auto_balloon
  45.   #--------------------------------------------------------------------------
  46.   # ● 公開メンバ変数の初期化
  47.   #--------------------------------------------------------------------------
  48.   alias _auto_balloon_init init_public_members
  49.   def init_public_members
  50.     _auto_balloon_init
  51.     @auto_balloon = 0
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ● プレイヤーからの距離を取得
  55.   #--------------------------------------------------------------------------
  56.   def distance_from_player
  57.     distance_x_from($game_player.x).abs + distance_y_from($game_player.y).abs
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● イベントページのセットアップ
  61.   #--------------------------------------------------------------------------
  62.   alias _auto_balloon_setup_page setup_page
  63.   def setup_page(new_page)
  64.     @auto_balloon = 0
  65.     _auto_balloon_setup_page(new_page)
  66.   end
  67. end

  68. class Sprite_Character < Sprite_Base
  69.   #--------------------------------------------------------------------------
  70.   # ● インクルード Rokan::Auto_Balloon
  71.   #--------------------------------------------------------------------------
  72.   include Rokan::Auto_Balloon
  73.   #--------------------------------------------------------------------------
  74.   # ● 解放
  75.   #--------------------------------------------------------------------------
  76.   alias _auto_balloon_dispose dispose
  77.   def dispose
  78.     dispose_auto_balloon
  79.     _auto_balloon_dispose
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● 常時再生フキダシアイコンの解放
  83.   #--------------------------------------------------------------------------
  84.   def dispose_auto_balloon
  85.     @bw = 10
  86.     @bx = -1
  87.     @auto_balloon_id = 0
  88.     if @auto_balloon_sprite
  89.       @auto_balloon_sprite.dispose
  90.       @auto_balloon_sprite = nil
  91.     end
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● フレーム更新
  95.   #--------------------------------------------------------------------------
  96.   alias _auto_balloon_update update
  97.   def update
  98.     update_auto_balloon
  99.     _auto_balloon_update
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● プレイヤーからの距離を取得
  103.   #--------------------------------------------------------------------------
  104.   def distance_from_player
  105.     @character.distance_from_player
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● 距離によるフキダシの透明度を取得
  109.   #--------------------------------------------------------------------------
  110.   def distance_balloon_opacity
  111.     DBO.zero? ? 255 : 255 - 50 * (distance_from_player - DBO)
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # ● 表示するフキダシのX座標を取得
  115.   #--------------------------------------------------------------------------
  116.   def auto_balloon_x
  117.     @bx * 32 + 64
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 表示するフキダシのY座標を取得
  121.   #--------------------------------------------------------------------------
  122.   def auto_balloon_y
  123.     (@auto_balloon_id - 1) * 32
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 常時再生フキダシアイコン表示の開始
  127.   #--------------------------------------------------------------------------
  128.   def start_auto_balloon
  129.     dispose_auto_balloon
  130.     @auto_balloon_id = @character.auto_balloon
  131.     @auto_balloon_sprite = Sprite.new(self.viewport)
  132.     @auto_balloon_sprite.bitmap = Cache.system("Balloon")
  133.     @auto_balloon_sprite.z = self.z + 200
  134.     @auto_balloon_sprite.ox = 16
  135.     @auto_balloon_sprite.oy = 32
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ● 常時再生フキダシアイコンの更新
  139.   #--------------------------------------------------------------------------
  140.   def update_auto_balloon
  141.     if @character.is_a?(Game_Event)
  142.       if @character.auto_balloon.zero? || !@balloon_duration.zero?
  143.         dispose_auto_balloon
  144.       else
  145.         start_auto_balloon if !@auto_balloon_sprite || @auto_balloon_id != @character.auto_balloon
  146.         @auto_balloon_sprite.x = self.x
  147.         @auto_balloon_sprite.y = self.y - self.height
  148.         @auto_balloon_sprite.opacity = distance_balloon_opacity
  149.         if @bw == 10
  150.           @bw = 0
  151.           @bx = @bx == 4 ? 0 : @bx.next
  152.           @auto_balloon_sprite.src_rect.set(auto_balloon_x, auto_balloon_y, 32, 32)
  153.         else
  154.           @bw = @bw.next
  155.         end
  156.       end
  157.     end
  158.   end
  159. end
复制代码



另外这个错位,稍微有点类似va本身的一个bug,就是当移动速度非整数(?)的时候地图事件图会错位1像素。
我用了下面这个脚本来修正,虽然用全新工程测试过和这个没关系(我也感觉没什么关系,但我也想不出显示心情错位还能跟什么有关系?)反正也贴一下供参考:
我折叠一下
  1. ##------
  2. ## Display rounding error fix created by Neon Black.
  3. ##
  4. ## When certain slow display panning speeds are used, events will improperly
  5. ## round floating values to determine their position on screen.  This causes
  6. ## them to appear off from the tilemap by a single pixel.  Though minor this is
  7. ## noticable.  This snippet fixes this behaviour.
  8. ##
  9. ## This snippet may be used in any project.
  10. ##
  11. ## -- Original Topic:
  12. ## [url]http://forums.rpgmakerweb.com/index.php?/topic/17448-event-jitter-fix-display-rounding-error-fix[/url]
  13. ##------
  14. class Game_Map ## Rounds X and Y display values DOWN so the nearest 32 is found.
  15.   def display_x
  16.     (@display_x * 32).floor.to_f / 32
  17.   end
  18.   
  19.   def display_y
  20.     (@display_y * 32).floor.to_f / 32
  21.   end
  22.   
  23.   def adjust_x(x)
  24.     if loop_horizontal? && x < display_x - (width - screen_tile_x) / 2
  25.       x - display_x + @map.width
  26.     else
  27.       x - display_x
  28.     end
  29.   end
  30.   
  31.   def adjust_y(y)
  32.     if loop_vertical? && y < display_y - (height - screen_tile_y) / 2
  33.       y - display_y + @map.height
  34.     else
  35.       y - display_y
  36.     end
  37.   end
  38. end
复制代码

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

本版积分规则

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

在本版发帖返回顶部