查看: 78|回复: 0

[转载发布] 翻转(水平/垂直)动画

[复制链接]
  • TA的每日心情
    开心
    2024-5-10 09:55
  • 签到天数: 37 天

    连续签到: 3 天

    [LV.5]常住居民I

    2028

    主题

    32

    回帖

    7260

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5184
    OK点
    16
    积分
    7260
    发表于 同元一千年八月三日(秋) | 显示全部楼层 |阅读模式
    (根据提问区问题如何将数据库动画水平翻转。编写。)


    RUBY 代码
    1. #==============================================================================
    2. # ■ 翻转动画 by 各种压力的猫君
    3. #------------------------------------------------------------------------------
    4. #  翻转显示动画,支持水平翻转和垂直翻转,理论支持任何地方的动画显示。
    5. #------------------------------------------------------------------------------
    6. #   使用方法:
    7. #     ① 扩大你的动画数据库上限
    8. #     ② 在设定段指定翻转开始编号
    9. #     ③ 需要翻转播放时播放指定编号的动画
    10. #   特殊动画:
    11. #     数据库中动画名以[nf]结尾的动画不会被翻转显示
    12. #     数据库中动画名以[hf]结尾的动画会水平翻转显示
    13. #     数据库中动画名以[vf]结尾的动画会垂直翻转显示
    14. #     识别标示中的字母可在设定段中更改(正则表达式)
    15. #     ※特殊动画的优先级高于数字指定※
    16. #==============================================================================
    17. #------------------------------------------------------------------------------
    18. # ● 设定段
    19. #------------------------------------------------------------------------------
    20. module FFAni # Full_Flip_Animation
    21.   # 水平翻转编号偏移量
    22.   # 若设定为100,则101号动画为1号动画的水平翻转(数据库中可以为空)
    23.   HF_ID = 100
    24.   # 垂直翻转编号偏移量(※请确保这个数字比上面一个数字大!※)
    25.   # 若设定为200,则201号动画为1号动画的垂直翻转(数据库中可以为空)
    26.   VF_ID = 200
    27.   # 特殊动画识别正则表达式
    28.   NF_Flag = /\[nf\]\z/ # 不翻转
    29.   HF_Flag = /\[hf\]\z/ # 水平翻转
    30.   VF_Flag = /\[vf\]\z/ # 垂直翻转
    31. end
    32. "         ┏━━━━━━━━━━━━━━━━━┓         "
    33. "         ┃※以下内容无一定脚本基础请勿修改※┃         "
    34. "         ┗━━━━━━━━━━━━━━━━━┛         "
    35. #==============================================================================
    36. # ■ RPG::Sprite
    37. #------------------------------------------------------------------------------
    38. #  追加了 RPGXP 使用的各种效果处理的精灵的类。
    39. #==============================================================================
    40. module RPG
    41.   class Sprite < ::Sprite
    42.     #------------------------------------------------------------------------
    43.     # ● 播放动画
    44.     #------------------------------------------------------------------------
    45.     def animation(animation, hit)
    46.       dispose_animation
    47.       @_animation = animation
    48.       #---------------------------------------------------
    49.       # 根据动画ID判断翻转情况
    50.       #---------------------------------------------------
    51.       if@_animation.id > FFAni::VF_ID    # 垂直
    52.         full_flip = 2
    53.         fixed_animation_id = @_animation.id - FFAni::VF_ID
    54.       elsif@_animation.id > FFAni::HF_ID# 水平
    55.         full_flip = 1
    56.         fixed_animation_id = @_animation.id - FFAni::HF_ID
    57.       end
    58.       #---------------------------------------------------
    59.       # 根据动画名判断翻转情况
    60.       #---------------------------------------------------
    61.       if(FFAni::NF_Flag =~ @_animation.name)  # 不翻转
    62.         full_flip = 0
    63.       elsif(FFAni::HF_Flag =~ @_animation.name)# 水平
    64.         full_flip = 1
    65.       elsif(FFAni::VF_Flag =~ @_animation.name)# 垂直
    66.         full_flip = 2
    67.       end
    68.       #---------------------------------------------------
    69.       # 修正参数
    70.       #   @_full_flip
    71.       #     0 : 不翻转
    72.       #     1 : 水平翻转
    73.       #     2 : 垂直翻转
    74.       #---------------------------------------------------
    75.       if full_flip == nil
    76.         @_full_flip = 0
    77.       else
    78.         @_full_flip = full_flip
    79.       end
    80.       unless fixed_animation_id == nil
    81.         @_animation = $data_animations[fixed_animation_id]
    82.       end
    83.       #---------------------------------------------------
    84.       returnif@_animation == nil
    85.       @_animation_hit = hit
    86.       @_animation_duration = @_animation.frame_max
    87.       animation_name = @_animation.animation_name
    88.       animation_hue = @_animation.animation_hue
    89.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
    90.       if @@_reference_count.include?(bitmap)
    91.         @@_reference_count[bitmap] += 1
    92.       else
    93.         @@_reference_count[bitmap] = 1
    94.       end
    95.       @_animation_sprites = []
    96.       if@_animation.position != 3ornot @@_animations.include?(animation)
    97.         for i in0..15
    98.           sprite = ::Sprite.new(self.viewport)
    99.           sprite.bitmap = bitmap
    100.           sprite.visible = false
    101.           @_animation_sprites.push(sprite)
    102.         end
    103.         unless @@_animations.include?(animation)
    104.           @@_animations.push(animation)
    105.         end
    106.       end
    107.       update_animation
    108.     end
    109.     #------------------------------------------------------------------------
    110.     # ● 播放循环动画
    111.     #------------------------------------------------------------------------
    112.     def loop_animation(animation)
    113.       returnif animation == @_loop_animation
    114.       dispose_loop_animation
    115.       @_loop_animation = animation
    116.       returnif@_loop_animation == nil
    117.       @_loop_animation_index = 0
    118.       animation_name = @_loop_animation.animation_name
    119.       animation_hue = @_loop_animation.animation_hue
    120.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
    121.       if @@_reference_count.include?(bitmap)
    122.         @@_reference_count[bitmap] += 1
    123.       else
    124.         @@_reference_count[bitmap] = 1
    125.       end
    126.       @_loop_animation_sprites = []
    127.       for i in0..15
    128.         sprite = ::Sprite.new(self.viewport)
    129.         sprite.bitmap = bitmap
    130.         sprite.visible = false
    131.         @_loop_animation_sprites.push(sprite)
    132.       end
    133.       update_loop_animation
    134.     end
    135.     #------------------------------------------------------------------------
    136.     # ● 设定动画Sprites
    137.     #------------------------------------------------------------------------
    138.     def animation_set_sprites(sprites, cell_data, position)
    139.       for i in0..15
    140.         sprite = sprites[i]
    141.         pattern = cell_data[i, 0]
    142.         if sprite == nilor pattern == nilor pattern == -1
    143.           sprite.visible = falseif sprite != nil
    144.           next
    145.         end
    146.         sprite.visible = true
    147.         sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
    148.         if position == 3
    149.           ifself.viewport != nil
    150.             sprite.x = self.viewport.rect.width / 2
    151.             sprite.y = self.viewport.rect.height - 160
    152.           else
    153.             sprite.x = 320
    154.             sprite.y = 240
    155.           end
    156.         else
    157.           sprite.x = self.x - self.ox + self.src_rect.width / 2
    158.           sprite.y = self.y - self.oy + self.src_rect.height / 2
    159.           sprite.y -= self.src_rect.height / 4if position == 0
    160.           sprite.y += self.src_rect.height / 4if position == 2
    161.         end
    162.         #---------------------------------------------------
    163.         # 脚本本体
    164.         #---------------------------------------------------
    165.         case@_full_flip
    166.         when0  # 啥也不做
    167.           sprite.x += cell_data[i, 1]
    168.           sprite.y += cell_data[i, 2]
    169.           sprite.angle = cell_data[i, 4]
    170.           sprite.mirror = (cell_data[i, 5] == 1)
    171.         when1  # 水平翻转
    172.           sprite.x -= cell_data[i, 1]
    173.           sprite.y += cell_data[i, 2]
    174.           sprite.angle = 360 - cell_data[i, 4]
    175.           sprite.mirror = (cell_data[i, 5] == 0)
    176.         when2  # 垂直翻转
    177.           sprite.x += cell_data[i, 1]
    178.           sprite.y -= cell_data[i, 2]
    179.           temp_angel = cell_data[i, 4] + 180
    180.           sprite.angle = temp_angel > 360 ? temp_angel - 360 : temp_angel   
    181.           sprite.mirror = (cell_data[i, 5] == 0)  
    182.         end
    183.         #---------------------------------------------------
    184.         sprite.z = 2000
    185.         sprite.ox = 96
    186.         sprite.oy = 96
    187.         sprite.zoom_x = cell_data[i, 3] / 100.0
    188.         sprite.zoom_y = cell_data[i, 3] / 100.0
    189.         sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
    190.         sprite.blend_type = cell_data[i, 7]
    191.       end
    192.     end
    193.   end
    194. end
    复制代码


    这没啥好截图的 = = b 用法很简单,范例不提供了。
                 本帖来自P1论坛作者各种压力的猫君,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=226947  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-20 21:47 , Processed in 0.046587 second(s), 43 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表