Project1
标题:
如何使damage方法能够顺次显示伤害?
[打印本页]
作者:
上帝的眼睛
时间:
2009-11-17 00:01
标题:
如何使damage方法能够顺次显示伤害?
本帖最后由 上帝的眼睛 于 2009-11-17 00:02 编辑
RT
我用的是在地图上显示伤害
脚本如下
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#
# 使用方法:
#
# ★、对角色显示伤害,如下3步:
#
# 1、设置伤害内容:$game_player.damage = 数值
# 注意:如果数值是负数,就变成补血的颜色了。
#
# 2、设置是否会心一击:$game_player.critical = true/false
# 如果不是会心一击,就不用这一步了
#
# 3、释放伤害:$game_player.damage_pop = true
#
#
# ★、对普通NPC和事件进行伤害,类似的3步:
#
# 1、设置伤害内容:$game_map.events[事件编号].damage = 数值
#
# 2、设置是否会心一击:$game_map.events[事件编号].critical = true/false
#
# 3、释放伤害:$game_map.events[事件编号].damage_pop = true
#
# 注意,事件编号是事件的ID号,如果目标是“本事件”,那么在事件编号输入@event_id
#
#------------------------------------------------------------------------------
# 预祝有人能早日做出华丽的ARPG来,别忘了到网站发布哦~
#------------------------------------------------------------------------------
class Sprite_Character < RPG::Sprite
alias carol3_66RPG_damage_pop_update update
def update
carol3_66RPG_damage_pop_update
if @character.damage_pop
damage(@character.damage, @character.critical)
@character.damage = nil
@character.critical = false
@character.damage_pop = false
end
end
end
class Game_Character
attr_accessor :damage_pop
attr_accessor :damage
attr_accessor :critical
alias carol3_66RPG_damage_pop_initialize initialize
def initialize
@damage_pop = false
@damage = 0
@critical = false
carol3_66RPG_damage_pop_initialize
end
end
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
复制代码
如果同时调用的话前面显示的伤害会被后面的覆盖而不显示
如何解决这个问题?
作者:
紫苏
时间:
2009-11-17 01:31
这个主要原因是 RPG::Sprite 中同时只会判断一个伤害动画的持续时间,而且当一个新的伤害显示时,旧的就会立刻被释放~解决方法是把伤害的精灵及其持续时间用一个容器组织起来,这样就可以同时存在多个伤害动画了,这个方法和以前的彩虹神剑所采用的方法基本相同……
注意红色部分是修改过的代码,灰色的是 RPG::Sprite 原本的内容:
module RPG
class Sprite < ::Sprite
def initialize(viewport = nil)
super(viewport)
@_whiten_duration = 0
@_appear_duration = 0
@_escape_duration = 0
@_collapse_duration = 0
#@_damage_duration = 0
@_damage_sprites = {}
@_animation_duration = 0
@_blink = false
end
def dispose
#dispose_damage
@_damage_sprites.each_key { |key|
dispose_damage(key)
}
dispose_animation
dispose_loop_animation
super
end
def damage(value, critical)
#dispose_damage
if value.is_a?(Numeric)
damage_string = value.abs.to_s
else
damage_string = value.to_s
end
bitmap = Bitmap.new(160, 48)
bitmap.font.name = "Arial Black"
bitmap.font.size = 32
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
if value.is_a?(Numeric) and value < 0
bitmap.font.color.set(176, 255, 144)
else
bitmap.font.color.set(255, 255, 255)
end
bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
if critical
bitmap.font.size = 20
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
end
#@_damage_sprites = ::Sprite.new(self.viewport)
#@_damage_sprite.bitmap = bitmap
#@_damage_sprite.ox = 80
#@_damage_sprite.oy = 20
#@_damage_sprite.x = self.x
#@_damage_sprite.y = self.y - self.oy / 2
#@_damage_sprite.z = 3000
#@_damage_duration = 40
_damage_sprite = ::Sprite.new(self.viewport)
_damage_sprite.bitmap = bitmap
_damage_sprite.ox = 80
_damage_sprite.oy = 20
_damage_sprite.x = self.x
_damage_sprite.y = self.y - self.oy / 2
_damage_sprite.z = 3000
@_damage_sprites[_damage_sprite] = 40
end
def dispose_damage
(_damage_sprite)
#if @_damage_sprite != nil
# @_damage_sprite.bitmap.dispose
# @_damage_sprite.dispose
# @_damage_sprite = nil
# @_damage_duration = 0
#end
if @_damage_sprites[_damage_sprite]
_damage_sprite.bitmap.dispose
_damage_sprite.dispose
@_damage_sprites.delete(_damage_sprite)
_damage_sprite = nil
end
end
def effect?
@_whiten_duration > 0 or
@_appear_duration > 0 or
@_escape_duration > 0 or
@_collapse_duration > 0 or
#@_damage_duration > 0 or
not @_damage_sprites.empty? or
@_animation_duration > 0
end
def update
super
if @_whiten_duration > 0
@_whiten_duration -= 1
self.color.alpha = 128 - (16 - @_whiten_duration) * 10
end
if @_appear_duration > 0
@_appear_duration -= 1
self.opacity = (16 - @_appear_duration) * 16
end
if @_escape_duration > 0
@_escape_duration -= 1
self.opacity = 256 - (32 - @_escape_duration) * 10
end
if @_collapse_duration > 0
@_collapse_duration -= 1
self.opacity = 256 - (48 - @_collapse_duration) * 6
end
#if @_damage_duration > 0
# @_damage_duration -= 1
# case @_damage_duration
# when 38..39
# @_damage_sprite.y -= 4
# when 36..37
# @_damage_sprite.y -= 2
# when 34..35
# @_damage_sprite.y += 2
# when 28..33
# @_damage_sprite.y += 4
# end
# @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
# if @_damage_duration == 0
# dispose_damage
# end
#end
@_damage_sprites.each_pair { |key, val|
if val > 0
@_damage_sprites[key] -= 1
case val - 1
when 38..39
key.y -= 4
when 36..37
key.y -= 2
when 34..35
key.y += 2
when 28..33
key.y += 4
end
key.opacity = 256 - (12 - val) * 32
if val - 1 == 0
dispose_damage(key)
end
end
}
if @_animation != nil and (Graphics.frame_count % 2 == 0)
@_animation_duration -= 1
update_animation
end
if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
update_loop_animation
@_loop_animation_index += 1
@_loop_animation_index %= @_loop_animation.frame_max
end
if @_blink
@_blink_count = (@_blink_count + 1) % 32
if @_blink_count < 16
alpha = (16 - @_blink_count) * 6
else
alpha = (@_blink_count - 16) * 6
end
self.color.set(255, 255, 255, alpha)
end
@@_animations.clear
end
end
end
作者:
上帝的眼睛
时间:
2009-11-17 15:42
这样做在事件里用等待1帧可以实现这样的效果
sdfjsdlkf.JPG
(4.52 KB, 下载次数: 0)
下载附件
保存到相册
2009-11-17 15:42 上传
,可是在脚本如何实现呢?
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1