查看: 4823|回复: 5

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

[复制链接]

(?????)

梦石
0
星屑
872
在线时间
1327 小时
注册时间
2011-7-18
回帖
3036

贵宾

发表于 2012-4-3 03:33:45 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 各种压力的猫君 于 2012-4-3 03:34 编辑

(根据提问区问题 如何将数据库动画水平翻转。编写。)


  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.   # 水平翻转编号偏移量
  23.   # 若设定为100,则101号动画为1号动画的水平翻转(数据库中可以为空)
  24.   HF_ID = 100
  25.   
  26.   # 垂直翻转编号偏移量(※请确保这个数字比上面一个数字大!※)
  27.   # 若设定为200,则201号动画为1号动画的垂直翻转(数据库中可以为空)
  28.   VF_ID = 200
  29.   
  30.   # 特殊动画识别正则表达式
  31.   NF_Flag = /\[nf\]\z/ # 不翻转
  32.   HF_Flag = /\[hf\]\z/ # 水平翻转
  33.   VF_Flag = /\[vf\]\z/ # 垂直翻转
  34.   
  35. end

  36. "         ┏━━━━━━━━━━━━━━━━━┓         "
  37. "         ┃※以下内容无一定脚本基础请勿修改※┃         "
  38. "         ┗━━━━━━━━━━━━━━━━━┛         "

  39. #==============================================================================
  40. # ■ RPG::Sprite
  41. #------------------------------------------------------------------------------
  42. #  追加了 RPGXP 使用的各种效果处理的精灵的类。
  43. #==============================================================================

  44. module RPG
  45.   class Sprite < ::Sprite
  46.     #------------------------------------------------------------------------
  47.     # ● 播放动画
  48.     #------------------------------------------------------------------------
  49.     def animation(animation, hit)
  50.       dispose_animation
  51.       @_animation = animation
  52.       #---------------------------------------------------
  53.       # 根据动画ID判断翻转情况
  54.       #---------------------------------------------------
  55.       if @_animation.id > FFAni::VF_ID    # 垂直
  56.         full_flip = 2
  57.         fixed_animation_id = @_animation.id - FFAni::VF_ID
  58.       elsif @_animation.id > FFAni::HF_ID # 水平
  59.         full_flip = 1
  60.         fixed_animation_id = @_animation.id - FFAni::HF_ID
  61.       end
  62.       #---------------------------------------------------
  63.       # 根据动画名判断翻转情况
  64.       #---------------------------------------------------
  65.       if(FFAni::NF_Flag =~ @_animation.name)  # 不翻转
  66.         full_flip = 0
  67.       elsif(FFAni::HF_Flag =~ @_animation.name) # 水平
  68.         full_flip = 1
  69.       elsif(FFAni::VF_Flag =~ @_animation.name) # 垂直
  70.         full_flip = 2
  71.       end
  72.       #---------------------------------------------------
  73.       # 修正参数
  74.       #   @_full_flip
  75.       #     0 : 不翻转
  76.       #     1 : 水平翻转
  77.       #     2 : 垂直翻转
  78.       #---------------------------------------------------
  79.       if full_flip == nil
  80.         @_full_flip = 0
  81.       else
  82.         @_full_flip = full_flip
  83.       end
  84.       unless fixed_animation_id == nil
  85.         @_animation = $data_animations[fixed_animation_id]
  86.       end
  87.       #---------------------------------------------------
  88.       return if @_animation == nil
  89.       @_animation_hit = hit
  90.       @_animation_duration = @_animation.frame_max
  91.       animation_name = @_animation.animation_name
  92.       animation_hue = @_animation.animation_hue
  93.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
  94.       if @@_reference_count.include?(bitmap)
  95.         @@_reference_count[bitmap] += 1
  96.       else
  97.         @@_reference_count[bitmap] = 1
  98.       end
  99.       @_animation_sprites = []
  100.       if @_animation.position != 3 or not @@_animations.include?(animation)
  101.         for i in 0..15
  102.           sprite = ::Sprite.new(self.viewport)
  103.           sprite.bitmap = bitmap
  104.           sprite.visible = false
  105.           @_animation_sprites.push(sprite)
  106.         end
  107.         unless @@_animations.include?(animation)
  108.           @@_animations.push(animation)
  109.         end
  110.       end
  111.       update_animation
  112.     end
  113.     #------------------------------------------------------------------------
  114.     # ● 播放循环动画
  115.     #------------------------------------------------------------------------
  116.     def loop_animation(animation)
  117.       return if animation == @_loop_animation
  118.       dispose_loop_animation
  119.       @_loop_animation = animation
  120.       return if @_loop_animation == nil
  121.       @_loop_animation_index = 0
  122.       animation_name = @_loop_animation.animation_name
  123.       animation_hue = @_loop_animation.animation_hue
  124.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
  125.       if @@_reference_count.include?(bitmap)
  126.         @@_reference_count[bitmap] += 1
  127.       else
  128.         @@_reference_count[bitmap] = 1
  129.       end
  130.       @_loop_animation_sprites = []
  131.       for i in 0..15
  132.         sprite = ::Sprite.new(self.viewport)
  133.         sprite.bitmap = bitmap
  134.         sprite.visible = false
  135.         @_loop_animation_sprites.push(sprite)
  136.       end
  137.       update_loop_animation
  138.     end
  139.     #------------------------------------------------------------------------
  140.     # ● 设定动画Sprites
  141.     #------------------------------------------------------------------------
  142.     def animation_set_sprites(sprites, cell_data, position)
  143.       for i in 0..15
  144.         sprite = sprites[i]
  145.         pattern = cell_data[i, 0]
  146.         if sprite == nil or pattern == nil or pattern == -1
  147.           sprite.visible = false if sprite != nil
  148.           next
  149.         end
  150.         sprite.visible = true
  151.         sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  152.         if position == 3
  153.           if self.viewport != nil
  154.             sprite.x = self.viewport.rect.width / 2
  155.             sprite.y = self.viewport.rect.height - 160
  156.           else
  157.             sprite.x = 320
  158.             sprite.y = 240
  159.           end
  160.         else
  161.           sprite.x = self.x - self.ox + self.src_rect.width / 2
  162.           sprite.y = self.y - self.oy + self.src_rect.height / 2
  163.           sprite.y -= self.src_rect.height / 4 if position == 0
  164.           sprite.y += self.src_rect.height / 4 if position == 2
  165.         end
  166.         #---------------------------------------------------
  167.         # 脚本本体
  168.         #---------------------------------------------------
  169.         case @_full_flip
  170.         when 0  # 啥也不做
  171.           sprite.x += cell_data[i, 1]
  172.           sprite.y += cell_data[i, 2]
  173.           sprite.angle = cell_data[i, 4]
  174.           sprite.mirror = (cell_data[i, 5] == 1)
  175.         when 1  # 水平翻转
  176.           sprite.x -= cell_data[i, 1]
  177.           sprite.y += cell_data[i, 2]
  178.           sprite.angle = 360 - cell_data[i, 4]
  179.           sprite.mirror = (cell_data[i, 5] == 0)
  180.         when 2  # 垂直翻转
  181.           sprite.x += cell_data[i, 1]
  182.           sprite.y -= cell_data[i, 2]
  183.           temp_angel = cell_data[i, 4] + 180
  184.           sprite.angle = temp_angel > 360 ? temp_angel - 360 : temp_angel   
  185.           sprite.mirror = (cell_data[i, 5] == 0)  
  186.         end
  187.         #---------------------------------------------------
  188.         sprite.z = 2000
  189.         sprite.ox = 96
  190.         sprite.oy = 96
  191.         sprite.zoom_x = cell_data[i, 3] / 100.0
  192.         sprite.zoom_y = cell_data[i, 3] / 100.0
  193.         sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  194.         sprite.blend_type = cell_data[i, 7]
  195.       end
  196.     end
  197.   end
  198. end
复制代码


这没啥好截图的 = = b 用法很简单,范例不提供了。

评分

参与人数 1星屑 +200 收起 理由
Kimu + 200 发布奖励

查看全部评分

老黄鸡

梦石
4
星屑
46133
在线时间
7978 小时
注册时间
2009-7-6
回帖
13342

MZ评测员RM创作大赛01组委会开拓者贵宾

发表于 2012-4-3 18:07:49 | 显示全部楼层
还以为要用到api,angle和mirror本身就挺慢的……

点评

记忆中相当慢,而且还有锯齿。  发表于 2012-4-3 18:09
RGDirect - DirectX驱动的RGSS,点我了解.
(排满,暂停)RM全系列成套系统定制请联系QQ1213237796
不接受对其他插件维护的委托
回复

使用道具 举报

梦石
0
星屑
65
在线时间
145 小时
注册时间
2011-7-14
回帖
36
发表于 2012-4-12 14:27:49 | 显示全部楼层
怎样复制代码!
只想完成自己所梦想的游戏!
只要自己努力
回复

使用道具 举报

小小的百鬼夜行<

梦石
0
星屑
54
在线时间
579 小时
注册时间
2010-7-29
回帖
2593

贵宾

发表于 2012-5-13 08:48:37 来自手机 | 显示全部楼层
其实我记得zoomxy改成负数就行……
某只PHP/HTML小白鼠→退屈の间


Cause I knew you were trouble when you walked in
So shame is on me now
I flow me to place i ve never been
till you put me down oh
Now Im lying on the cold hard ground
回复

使用道具 举报

梦石
0
星屑
49
在线时间
186 小时
注册时间
2012-5-8
回帖
939
发表于 2012-5-13 23:09:30 | 显示全部楼层
有图片或范例吗?能让别人更好的理解。
看什么看,没看过大坑啊!
-------------------------炫翼-----------------------------
剧情:4%
地图:2%
系统:7%
优化:3%
脚本:25%
--------------------------炫翼----------------------------

      工作室


广告位招租....  
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2012-5-16 13:32:01 | 显示全部楼层
怎么用啊?表示纠结中
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部