查看: 3613|回复: 2

[已经解决] 一个状态窗口中有一个人物行走踏步动态图脚本如何实现。

[复制链接]
梦石
0
星屑
208
在线时间
420 小时
注册时间
2020-1-11
回帖
175
发表于 2021-3-30 18:05:50 | 显示全部楼层 |阅读模式

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

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

×
人物行走怎么描绘我能实现,但是要使之走动起来就茫然了。求指教。
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2021-3-30 19:04:10 | 显示全部楼层
  1. # Script:   Draw Animated Characters In Windows
  2. # Author:   Evgenij
  3. # Date:     07.01.2015
  4. # Version:  1.0a
  5. #
  6. # Description: With this script you can add a new method to windows
  7. #              which will draw animated characters
  8. #
  9. #              You need to include the EVG::AnimatedDrawCharacter Module
  10. #              into a Window class.
  11. #              Then you can use this methods:
  12. #                draw_animated_character(character_name, character_index, x, y, direction = 2)
  13. #                clear_animated_characters # clears all the characters from windows content
  14. #                      # and stops drawing them
  15. module EVG
  16.   # Adds a new method to a window when included:
  17.   #   draw_animated_character(character_name, character_index, x, y, direction = 2)
  18.   module AnimatedDrawCharacter
  19.     # wait between each character frame (in frames)
  20.     WAIT_BETWEEN_FRAMES = 10

  21.     def initialize(*args)
  22.       super(*args)
  23.       create_animation_state_machine
  24.     end

  25.     def create_animation_state_machine
  26.       @anim_state_machine = AnimationStateMachine.new
  27.       @animated_characters = []
  28.     end

  29.     def draw_animated_character(character_name, character_index, x, y, direction = 2)
  30.       return unless character_name
  31.       bitmap = Cache.character(character_name)
  32.       sign = character_name[/^[\!\$]./]
  33.       if sign && sign.include?('$')
  34.         cw = bitmap.width / 3
  35.         ch = bitmap.height / 4
  36.       else
  37.         cw = bitmap.width / 12
  38.         ch = bitmap.height / 8
  39.       end
  40.       @animated_characters << [character_name, character_index, x, y, cw, ch, direction]
  41.       @animated_characters.uniq!
  42.       update_animated_characters
  43.     end

  44.     def clear_animated_characters
  45.       @animated_characters.each do |arr|
  46.         contents.clear_rect(arr[2] - arr[4] / 2, arr[3] - arr[5], arr[4], arr[5])
  47.       end
  48.       @animated_characters = []
  49.     end

  50.     def update
  51.       super
  52.       @anim_state_machine.update
  53.       update_animated_characters if @anim_state_machine.changed?
  54.     end

  55.     def update_animated_characters
  56.       @animated_characters.each{|arr| update_animated_character(arr)}
  57.     end

  58.     # Param looks like this: [character_name, character_index, x, y, ch, cw, direction]
  59.     def update_animated_character(arr)
  60.       contents.clear_rect(arr[2] - arr[4] / 2, arr[3] - arr[5], arr[4], arr[5])
  61.       bitmap = Cache.character(arr[0])
  62.       src_rect = @anim_state_machine.get_rect(arr[1], arr[4], arr[5], arr[6])
  63.       contents.blt(arr[2] - arr[4] / 2, arr[3] - arr[5], bitmap, src_rect)
  64.     end
  65.   end

  66.   class AnimationStateMachine
  67.     def initialize
  68.       super
  69.       @anime_count = 0
  70.       @pattern = 1
  71.       @frame_count = AnimatedDrawCharacter::WAIT_BETWEEN_FRAMES
  72.     end

  73.     def get_rect(char_index, cw, ch, d)
  74.       pattern = @pattern < 3 ? @pattern : 1
  75.       sx = (char_index % 4 * 3 + pattern) * cw
  76.       sy = (char_index / 4 * 4 + (d - 2) / 2) * ch
  77.       Rect.new(sx, sy, cw, ch)
  78.     end

  79.     def update
  80.       update_pattern
  81.     end

  82.     def update_pattern
  83.       @anime_count += 1
  84.       if @anime_count > @frame_count
  85.         @pattern = (@pattern + 1) % 4
  86.         @anime_count = 0
  87.       end
  88.     end

  89.     def changed?
  90.       @anime_count == 0
  91.     end
  92.   end
  93. end
复制代码
回复 1 0

使用道具 举报

梦石
0
星屑
208
在线时间
420 小时
注册时间
2020-1-11
回帖
175
 楼主| 发表于 2021-3-30 21:44:27 | 显示全部楼层
alexncf125 发表于 2021-3-30 19:04
# Script:   Draw Animated Characters In Windows
# Author:   Evgenij
# Date:     07.01.2015

看起来有点复杂,让我花点时间研究一下。谢谢。
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部