赞 | 2 |
VIP | 143 |
好人卡 | 1 |
积分 | 1 |
经验 | 216792 |
最后登录 | 2019-10-10 |
在线时间 | 24 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 61
- 在线时间
- 24 小时
- 注册时间
- 2008-8-5
- 帖子
- 1924
|
插入这个脚本,主要功能是给 Sprite_character 定义一个是否抖动的布尔型成员 @shaking,当这个成员为真时就让精灵的屏幕 x 坐标在当前位置循环左右摆动,否则固定~
class Sprite_Character < RPG::Sprite
attr_accessor :shaking
#--------------------------------------------------------------------------
# ● 初始化对像
# viewport : 查看端口
# character : 角色 (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
@shaking = false
@shaking_cnt = 0
@shaking_dir = 0
update
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
# 元件 ID、文件名、色相与现在的情况存在差异的情况下
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# 记忆元件 ID 与文件名、色相
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# 元件 ID 为有效值的情况下
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# 元件 ID 为无效值的情况下
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# 设置可视状态
self.visible = (not @character.transparent)
# 图形是角色的情况下
if @tile_id == 0
# 设置传送目标的矩形
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# 设置脚本的坐标
if @shaking
offset = 2
self.x = @shaking_cnt + @character.screen_x
@shaking_cnt = @shaking_dir == 0 ? @shaking_cnt + 1 : @shaking_cnt - 1
if @shaking_cnt >= offset || @shaking_cnt <= -offset
@shaking_dir ^= 1
end
else
self.x = @character.screen_x
end
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# 设置不透明度、合成方式、茂密
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# 动画
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
class Scene_Map
attr :spriteset
end
class Spriteset_Map
attr :character_sprites
end
然后在事件脚本中调用:$scene.spriteset.character_sprites[0].
shaking = true 就能让地图中的第一个事件(编号最小的事件)开始抖动~
相同的语句把 true 改为 false 就能使其停止抖动
另外如果想让主角抖动,在 [..] 中填一个 -1 就行了,会自动定位到数组中的最后一个元素——主角的精灵 版主对此帖的认可:『强大!顺手抱走了...』,积分『+100』。 系统信息:本贴由本区版主认可为正确答案,66RPG感谢您的热情解答~ |
|