Project1
标题:
没看懂只知道的向windows添加新方法!该怎么使用这个脚本?
[打印本页]
作者:
shengfeng
时间:
2021-4-3 16:11
标题:
没看懂只知道的向windows添加新方法!该怎么使用这个脚本?
# Script: Draw Animated Characters In Windows
# Author: Evgenij
# Date: 07.01.2015
# Version: 1.0a
#
# Description: With this script you can add a new method to windows
# which will draw animated characters
#
# You need to include the EVG::AnimatedDrawCharacter Module
# into a Window class.
# Then you can use this methods:
# draw_animated_character(character_name, character_index, x, y, direction = 2)
# clear_animated_characters # clears all the characters from windows content
# # and stops drawing them
# which will draw animated characters
module EVG
# Adds a new method to a window when included:
# draw_animated_character(character_name, character_index, x, y, direction = 2)
module AnimatedDrawCharacter
# wait between each character frame (in frames)
WAIT_BETWEEN_FRAMES = 10
def initialize(*args)
super(*args)
create_animation_state_machine
end
def create_animation_state_machine
@anim_state_machine = AnimationStateMachine.new
@animated_characters = []
end
def draw_animated_character(character_name, character_index, x, y, direction = 2)
return unless character_name
bitmap = Cache.character(character_name)
sign = character_name[/^[\!\$]./]
if sign && sign.include?(')
cw = bitmap.width / 3
ch = bitmap.height / 4
else
cw = bitmap.width / 12
ch = bitmap.height / 8
end
@animated_characters << [character_name, character_index, x, y, cw, ch, direction]
@animated_characters.uniq!
update_animated_characters
end
def clear_animated_characters
@animated_characters.each do |arr|
contents.clear_rect(arr[2] - arr[4] / 2, arr[3] - arr[5], arr[4], arr[5])
end
@animated_characters = []
end
def update
super
@anim_state_machine.update
update_animated_characters if @anim_state_machine.changed?
end
def update_animated_characters
@animated_characters.each{|arr| update_animated_character(arr)}
end
# Param looks like this: [character_name, character_index, x, y, ch, cw, direction]
def update_animated_character(arr)
contents.clear_rect(arr[2] - arr[4] / 2, arr[3] - arr[5], arr[4], arr[5])
bitmap = Cache.character(arr[0])
src_rect = @anim_state_machine.get_rect(arr[1], arr[4], arr[5], arr[6])
contents.blt(arr[2] - arr[4] / 2, arr[3] - arr[5], bitmap, src_rect)
end
end
class AnimationStateMachine
def initialize
super
@anime_count = 0
@pattern = 1
@frame_count = AnimatedDrawCharacter::WAIT_BETWEEN_FRAMES
end
def get_rect(char_index, cw, ch, d)
pattern = @pattern < 3 ? @pattern : 1
sx = (char_index % 4 * 3 + pattern) * cw
sy = (char_index / 4 * 4 + (d - 2) / 2) * ch
Rect.new(sx, sy, cw, ch)
end
def update
update_pattern
end
def update_pattern
@anime_count += 1
if @anime_count > @frame_count
@pattern = (@pattern + 1) % 4
@anime_count = 0
end
end
def changed?
@anime_count == 0
end
end
end
复制代码
作者:
alexncf125
时间:
2021-4-3 16:40
本帖最后由 alexncf125 于 2021-4-3 17:01 编辑
class Window_Base < Window
include EVG::AnimatedDrawCharacter
alias window_base_initialize_evg_animated_draw_character initialize
def initialize(x, y, width, height)
window_base_initialize_evg_animated_draw_character(x, y, width, height)
4.times {|i| draw_animated_character("Actor#{i + 1}", i, 16 + 32 * i , 32 * (i + 1), [2, 4, 6, 8].sample)}
end
end
复制代码
看懂没
作者:
shengfeng
时间:
2021-4-3 18:48
能看懂!不过显示动态行走图应该在对应的窗口中使用?在wⅰndow_base中使用在任何窗囗中都会显示动态行走图!
作者:
alexncf125
时间:
2021-4-3 19:58
我咋知你想在哪个窗口中使用...wⅰndow_base只是个示例好不
作者:
shengfeng
时间:
2021-4-3 22:05
alexncf125 发表于 2021-4-3 19:58
我咋知你想在哪个窗口中使用...wⅰndow_base只是个示例好不
战斗中、菜单中和状态中
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1