设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
Project1 查看内容

damage伤害的显示改造 (日本教学翻译)

2006-2-5 00:00| 发布者: 柳柳| 查看: 6656| 评论: 0|原作者: 不详

摘要:    作者 原贴:http://windmesser.tm.land.to/rgss/rgss005.html 版本与更新  2006年1月 相关网址 点此进入翻译贴 范例工程 教程内容 ★RGSS教学5★标题:《伤害的显示改造》简介:改
  

作者

原贴:http://windmesser.tm.land.to/rgss/rgss005.html

版本与更新

 2006年1月

相关网址

点此进入翻译贴

范例工程



教程内容

★RGSS教学5★
标题:《伤害的显示改造》
简介:改造损伤表示的处理部分,变更RMXP的RPG类。此处只做一些基本方法的介绍。
地址:http://windmesser.tm.land.to/rgss/rgss005.html
注释:此段教学翻译结果和原文表述有较大出入,只保证结果是完全正确的。
翻译:柳柳


首先,先要了解伤害表示的脚本写在哪儿。即使在整个脚本搜damage也获得不了什么有用内容。这时请按F1打开菜蛋翻译的中文RMXP帮助文件,找到RPG::Sprite类。

RPG::Sprite

module RPG
 class Sprite < ::Sprite
   @@_animations = []
   @@_reference_count = {}
.....(无关函数就不写了,请自己看帮助).....
   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_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_duration = 40
   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
     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

其中RPG::Sprite::damage,也就是上面脚本中的def damage(value, critical)为伤害表示部分。

value 为表示的内容,如数字,或者“MISS”字样等。critical 表示会心一击。当critical==true的时候会显示CRITICAL字样。

RPG::Sprite::damage 文字显示部分表示設定(字体等内容)

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)

在这儿描画除了“MISS”的部分以外的伤害。第一、二行设定了字体、文字大小
下面四行用Bitmap.draw_text()描绘4次黑色文字,是为了制作黑色的文字勾边(虽然会有一点点延迟)。最后一段表示通常的损伤用白色,恢复的用绿色。

RPG::Sprite::damage Critical部分表示設定

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

和普通文字部分差不多,一样是先黑色勾边,再用白色绘制。

RPG::Sprite::damage 改変

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(240, 72)
 bitmap.font.name = "隶书"
 bitmap.font.bold = true
 bitmap.font.italic = true
 bitmap.font.size = 40

 bitmap.font.color.set(0, 0, 0)
 bitmap.draw_text(-1, 12-1, 240, 54, damage_string, 1)
 bitmap.draw_text(+1, 12-1, 240, 54, damage_string, 1)
 bitmap.draw_text(-1, 12+1, 240, 54, damage_string, 1)
 bitmap.draw_text(+1, 12+1, 240, 54, 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, 240, 54, damage_string, 1)

 if critical
   bitmap.font.bold = false
   bitmap.font.italic = true
   bitmap.font.size = 25

   bitmap.font.color.set(0, 0, 0)
   bitmap.draw_text(-1, -1, 240, 25, "会心一击", 1)
   bitmap.draw_text(+1, -1, 240, 25, "会心一击", 1)
   bitmap.draw_text(-1, +1, 240, 25, "会心一击", 1)
   bitmap.draw_text(+1, +1, 240, 25, "会心一击", 1)

   bitmap.font.color.set(255, 255, 255)
   bitmap.draw_text(0, 0, 240, 25, "会心一击", 1)

 end
 @_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_duration = 40
end

具体效果请看图:上图为修改前,下图为修改后


下面修改文字弹跳方式。
@_damage_duration代入了文字弹跳时间,其数值从40逐渐减小到0(上面修改过的damage脚本的@_damage_duration = 40设定弹跳时间),并在这个过程中弹跳文字。

RPG::Sprite::update

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
 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

红色文字部分就是文字运动的过程。可以自己随便定义一些路线。比如改为如下:

RPG::Sprite::update 改変

if @_damage_duration > 0
 @_damage_duration -= 1
 case @_damage_duration
 when 1..30
   @_damage_sprite.zoom_x += 0.05
   @_damage_sprite.zoom_y -= 0.05
   @_damage_sprite.x -= 1
   @_damage_sprite.y += 1
 @_damage_sprite.opacity = @_damage_duration * 5 + 50
 if @_damage_duration == 0
   dispose_damage
 end
end

则文字是一个渐变消失过程(变宽变矮)。这个讲座主要是希望大家碰到问题能够自己搜索检查,不要总是指望别人的脚本。


 

教程的通用说明

本站发布的教程,大多经过一些测试,应该都能够实现相应功能。但不保证所有的教程都是最优化的制作方法。

相关问题,点击发布贴进行讨论。谢谢您的鼓励与支持。


鲜花
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-20 17:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部