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