赞 | 95 |
VIP | 77 |
好人卡 | 113 |
积分 | 69 |
经验 | 147345 |
最后登录 | 2024-9-22 |
在线时间 | 7028 小时 |
Lv4.逐梦者 (版主)
- 梦石
- 0
- 星屑
- 6901
- 在线时间
- 7028 小时
- 注册时间
- 2013-11-2
- 帖子
- 1344
|
本帖最后由 RaidenInfinity 于 2016-10-20 11:17 编辑
#地图上动画朝向脚本 #by RaidenInfinity class Sprite_Character < Sprite_Base def ani_four_dir #套用四朝向的动画,角色面向哪儿动画就朝向哪儿 [58] #在这里增加想要套用的动画ID,别忘了逗号 例子:[1,2,3,4] end def ani_two_dir #套用二朝向的动画,面向上或下时不变,左或右等同朝右 [] #在这里增加想要套用的动画ID,别忘了逗号 例子:[55,66,77,88] end #----------------------------------------------------------------------------- #以下的除非你知道你在干嘛,否则请勿触碰! def char_direction @character.direction end def char_ani_id @character.animation_id end alias :ani_dir_animation_set_sprites :animation_set_sprites def animation_set_sprites(frame) if ani_four_dir.include?(char_ani_id) animation_set_sprites_d(frame,0) return elsif ani_two_dir.include?(char_ani_id) animation_set_sprites_d(frame,1) return end ani_dir_animation_set_sprites(frame) end def animation_set_sprites_d(frame,type) cell_data = frame.cell_data @ani_sprites.each_with_index do |sprite, i| next unless sprite pattern = cell_data[i, 0] if !pattern || pattern < 0 sprite.visible = false next end #y fix a_x = @ani_ox a_y = @ani_oy a_y -= self.height / 2 if char_direction == 4 || char_direction == 6 #y fix end sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2 sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern % 100 / 5 * 192, 192, 192) if @ani_mirror sprite.x = a_x - cell_data[i, 1] sprite.y = a_y + cell_data[i, 2] sprite.angle = (360 - cell_data[i, 4]) sprite.mirror = (cell_data[i, 5] == 0) else sprite.x = a_x + cell_data[i, 1] sprite.y = a_y + cell_data[i, 2] sprite.angle = cell_data[i, 4] sprite.mirror = (cell_data[i, 5] == 1) end #direction change here if type == 0 && char_direction != 8 sprite.angle = get_fdir_angle(sprite.angle) coord = get_fdir_coord([sprite.x - a_x,sprite.y - a_y]) sprite.x = coord[0] + a_x sprite.y = coord[1] + a_y elsif type == 1 && (char_direction == 4 || char_direction == 6) sprite.angle = get_tdir_angle(sprite.angle) coord = get_tdir_coord([sprite.x - a_x,sprite.y - a_y]) sprite.x = coord[0] + a_x sprite.y = coord[1] + a_y end #direction change end sprite.z = self.z + 300 + i sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end def get_fdir_angle(angle) case(char_direction) when 4; angle += 90 when 6; angle -= 90 when 2; angle += 180 end angle = angle - 360 if angle > 360 angle = 360 - angle if angle < 0 return angle end def get_tdir_angle(angle) angle -= 90 angle = 360 - angle if angle < 0 return angle end def get_fdir_coord(vec) return m_mult(get_std_mat(char_direction),vec) end def get_tdir_coord(vec) return m_mult(get_std_mat(6),vec) end def m_mult(std,vec) a = [0,0] a[0] = std[0] * vec[0] + std[1] * vec[1] a[1] = std[2] * vec[0] + std[3] * vec[1] return a end def get_std_mat(direction) case(direction) when 4; return [0,1,-1,0] when 6; return [0,-1,1,0] when 2; return [-1,0,0,-1] end [1,0,0,1] end end
#地图上动画朝向脚本
#by RaidenInfinity
class Sprite_Character < Sprite_Base
def ani_four_dir #套用四朝向的动画,角色面向哪儿动画就朝向哪儿
[58] #在这里增加想要套用的动画ID,别忘了逗号 例子:[1,2,3,4]
end
def ani_two_dir #套用二朝向的动画,面向上或下时不变,左或右等同朝右
[] #在这里增加想要套用的动画ID,别忘了逗号 例子:[55,66,77,88]
end
#-----------------------------------------------------------------------------
#以下的除非你知道你在干嘛,否则请勿触碰!
def char_direction
@character.direction
end
def char_ani_id
@character.animation_id
end
alias :ani_dir_animation_set_sprites :animation_set_sprites
def animation_set_sprites(frame)
if ani_four_dir.include?(char_ani_id)
animation_set_sprites_d(frame,0)
return
elsif ani_two_dir.include?(char_ani_id)
animation_set_sprites_d(frame,1)
return
end
ani_dir_animation_set_sprites(frame)
end
def animation_set_sprites_d(frame,type)
cell_data = frame.cell_data
@ani_sprites.each_with_index do |sprite, i|
next unless sprite
pattern = cell_data[i, 0]
if !pattern || pattern < 0
sprite.visible = false
next
end
#y fix
a_x = @ani_ox
a_y = @ani_oy
a_y -= self.height / 2 if char_direction == 4 || char_direction == 6
#y fix end
sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
sprite.visible = true
sprite.src_rect.set(pattern % 5 * 192,
pattern % 100 / 5 * 192, 192, 192)
if @ani_mirror
sprite.x = a_x - cell_data[i, 1]
sprite.y = a_y + cell_data[i, 2]
sprite.angle = (360 - cell_data[i, 4])
sprite.mirror = (cell_data[i, 5] == 0)
else
sprite.x = a_x + cell_data[i, 1]
sprite.y = a_y + cell_data[i, 2]
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
end
#direction change here
if type == 0 && char_direction != 8
sprite.angle = get_fdir_angle(sprite.angle)
coord = get_fdir_coord([sprite.x - a_x,sprite.y - a_y])
sprite.x = coord[0] + a_x
sprite.y = coord[1] + a_y
elsif type == 1 && (char_direction == 4 || char_direction == 6)
sprite.angle = get_tdir_angle(sprite.angle)
coord = get_tdir_coord([sprite.x - a_x,sprite.y - a_y])
sprite.x = coord[0] + a_x
sprite.y = coord[1] + a_y
end
#direction change end
sprite.z = self.z + 300 + i
sprite.ox = 96
sprite.oy = 96
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
sprite.blend_type = cell_data[i, 7]
end
end
def get_fdir_angle(angle)
case(char_direction)
when 4; angle += 90
when 6; angle -= 90
when 2; angle += 180
end
angle = angle - 360 if angle > 360
angle = 360 - angle if angle < 0
return angle
end
def get_tdir_angle(angle)
angle -= 90
angle = 360 - angle if angle < 0
return angle
end
def get_fdir_coord(vec)
return m_mult(get_std_mat(char_direction),vec)
end
def get_tdir_coord(vec)
return m_mult(get_std_mat(6),vec)
end
def m_mult(std,vec)
a = [0,0]
a[0] = std[0] * vec[0] + std[1] * vec[1]
a[1] = std[2] * vec[0] + std[3] * vec[1]
return a
end
def get_std_mat(direction)
case(direction)
when 4; return [0,1,-1,0]
when 6; return [0,-1,1,0]
when 2; return [-1,0,0,-1]
end
[1,0,0,1]
end
end
MAGIC. |
评分
-
查看全部评分
|