[增补功能]循环动画
做遊戲時候寫出來的副産品作用:在固定位置不停播放循環動畫,如同窗口一樣。
調用方法:Sprite_Animation.new(x,y,z)
類方法:
設置/更改循環動畫ID:
.id =
暫停:
.pause = true
隱藏:
.visible = false
坐標:
.x =
.y =
.z =#==============================================================================# ■ Sprite_Animation / 動畫使用增強#------------------------------------------------------------------------------class Sprite_Animation < RPG::Sprite#--------------------------------------------------------------------------# ● 取得動畫ID#--------------------------------------------------------------------------attr_accessor :idattr_accessor :pauseattr_accessor :visible#--------------------------------------------------------------------------# ● 初始化物件# viewport : 顯示連接埠#--------------------------------------------------------------------------def initialize(x=0,y=0,z=5000) @viewport = Viewport.new(0, 0, 640, 480) @viewport.z = z super(@viewport) self.id = 0 self.pause = false self.visible = true # 設定活動區塊的座標 self.x = x self.y = y self.z = z updateendalias old_update update#--------------------------------------------------------------------------# ● 更新畫面#--------------------------------------------------------------------------def update if self.pause or self.id == 0 return else old_update endend#--------------------------------------------------------------------------# ● 一次性用完即弃的动画#--------------------------------------------------------------------------def self.show(id,x=0,y=0) s = self.new(x, y) a = $data_animations s.animation(a,false) while s.effect? s.old_update Graphics.update end s.disposeend#--------------------------------------------------------------------------# ● 釋放#--------------------------------------------------------------------------def dispose (self.bitmap.dispose) unless (self.bitmap == nil) @viewport.dispose @viewport.dispose superend#--------------------------------------------------------------------------# ● 更改動畫#--------------------------------------------------------------------------def id=(int) @id = int if id == 0 dispose_loop_animation return end animation = $data_animations loop_animation(animation)end#--------------------------------------------------------------------------# ● 更改可視化#--------------------------------------------------------------------------def visible=(bool) super(bool) if bool animation = $data_animations loop_animation(animation) else dispose_loop_animation endend#--------------------------------------------------------------------------# ● 單幀設置算法#--------------------------------------------------------------------------def animation_set_sprites(sprites, cell_data, position) for i in 0..15 sprite = sprites pattern = cell_data if sprite == nil or pattern == nil or pattern == -1 sprite.visible = false if sprite != nil next end sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192) if position == 3 if self.viewport != nil sprite.x = self.viewport.rect.width / 2 sprite.y = self.viewport.rect.height - 160 else sprite.x = 320 sprite.y = 240 end else sprite.x = self.x - self.ox + self.src_rect.width / 2 sprite.y = self.y - self.oy + self.src_rect.height / 2 sprite.y -= self.src_rect.height / 4 if position == 0 sprite.y += self.src_rect.height / 4 if position == 2 end sprite.x += cell_data sprite.y += cell_data sprite.z = 2000 sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data / 100.0 sprite.zoom_y = cell_data / 100.0 sprite.angle = cell_data sprite.mirror = (cell_data == 1) sprite.opacity = cell_data * self.opacity / 255.0 sprite.blend_type = cell_data endendend复制代码技術含量基本上等於零……
不擅長表達,需要播放多個動畫的人應該知道有甚麽用途==|||
本帖来自P1论坛作者禾西,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=84595若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]