设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1314|回复: 2
打印 上一主题 下一主题

[已经过期] 地图播放动画 切换窗口会消失【已放弃】

[复制链接]

Lv1.梦旅人

梦石
0
星屑
176
在线时间
359 小时
注册时间
2015-3-29
帖子
125
跳转到指定楼层
1
发表于 2015-7-11 20:13:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 Coder7447 于 2015-7-16 12:04 编辑

这个问题处理会牵扯到很多问题,已经放弃处理了。麻烦版本大人挂下过期。


大家好,当地图上播放动画的时候,如何切换到窗口界面返回地图时原先的动画就会被清除,请问这该如何解决?
我用了多动画脚本,麻烦帮忙看下

RUBY 代码复制
  1. #--------------------------------------------------
  2. # 此脚本来自[url]www.66RPG.com[/url],使用请保留此信息
  3. #--------------------------------------------------
  4. module RPG
  5.   class Sprite < ::Sprite
  6.     def initialize(viewport = nil)
  7.       super(viewport)
  8.       @_whiten_duration = 0
  9.       @_appear_duration = 0
  10.       @_escape_duration = 0
  11.       @_collapse_duration = 0
  12.       @_damage_duration = 0
  13.       @_animation_duration = 0
  14.       @_blink = false
  15.       @_animation = []
  16.     end
  17.     def animation(animation, hit)
  18.       return if animation == nil
  19.       num = @_animation.size
  20.       @_animation.push([animation, hit, animation.frame_max, []])
  21.       bitmap = RPG::Cache.animation(animation.animation_name,
  22.                                     animation.animation_hue)
  23.       if @@_reference_count.include?(bitmap)
  24.         @@_reference_count[bitmap] += 1
  25.       else
  26.         @@_reference_count[bitmap] = 1
  27.       end
  28.       if @_animation[num][0] != 3 or not @@_animations.include?(animation)
  29.         for i in 0..15
  30.           sprite = ::Sprite.new
  31.           sprite.bitmap = bitmap
  32.           sprite.visible = false
  33.           @_animation[num][3].push(sprite)
  34.         end
  35.         unless @@_animations.include?(animation)
  36.           @@_animations.push(animation)
  37.         end
  38.       end
  39.       update_animation(@_animation[num])
  40.     end
  41.     def loop_animation(animation)
  42.       return if animation == @_loop_animation
  43.       dispose_loop_animation
  44.       @_loop_animation = animation
  45.       return if @_loop_animation == nil
  46.       @_loop_animation_index = 0
  47.       animation_name = @_loop_animation.animation_name
  48.       animation_hue = @_loop_animation.animation_hue
  49.       bitmap = RPG::Cache.animation(animation_name, animation_hue)
  50.       if @@_reference_count.include?(bitmap)
  51.         @@_reference_count[bitmap] += 1
  52.       else
  53.         @@_reference_count[bitmap] = 1
  54.       end
  55.       @_loop_animation_sprites = []
  56.       for i in 0..15
  57.         sprite = ::Sprite.new
  58.         sprite.bitmap = bitmap
  59.         sprite.visible = false
  60.         @_loop_animation_sprites.push(sprite)
  61.       end
  62.       # update_loop_animation
  63.     end
  64.     def dispose_animation
  65.       for anime in @_animation.reverse
  66.         sprite = anime[3][0]
  67.         if sprite != nil
  68.           @@_reference_count[sprite.bitmap] -= 1
  69.           if @@_reference_count[sprite.bitmap] == 0
  70.             sprite.bitmap.dispose
  71.           end
  72.         end
  73.         for sprite in anime[3]
  74.           sprite.dispose
  75.         end
  76.         @_animation.delete(anime)
  77.       end
  78.     end
  79.  
  80.     def update
  81.       super
  82.       if @_whiten_duration > 0
  83.         @_whiten_duration -= 1
  84.         self.color.alpha = 128 - (16 - @_whiten_duration) * 10
  85.       end
  86.       if @_appear_duration > 0
  87.         @_appear_duration -= 1
  88.         self.opacity = (16 - @_appear_duration) * 16
  89.       end
  90.       if @_escape_duration > 0
  91.         @_escape_duration -= 1
  92.         self.opacity = 256 - (32 - @_escape_duration) * 10
  93.       end
  94.       if @_collapse_duration > 0
  95.         @_collapse_duration -= 1
  96.         self.opacity = 256 - (48 - @_collapse_duration) * 6
  97.       end
  98.       if @_damage_duration > 0
  99.         @_damage_duration -= 1
  100.         case @_damage_duration
  101.         when 38..39
  102.           @_damage_sprite.y -= 4
  103.         when 36..37
  104.           @_damage_sprite.y -= 2
  105.         when 34..35
  106.           @_damage_sprite.y += 2
  107.         when 28..33
  108.           @_damage_sprite.y += 4
  109.         end
  110.         @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
  111.         if @_damage_duration == 0
  112.           dispose_damage
  113.         end
  114.       end
  115.       for anime in @_animation
  116.         if (Graphics.frame_count % 2 == 0)
  117.           anime[2] -= 1
  118.           update_animation(anime)
  119.         end
  120.       end
  121.       if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)
  122.         update_loop_animation
  123.         @_loop_animation_index += 1
  124.         @_loop_animation_index %= @_loop_animation.frame_max
  125.       end
  126.       if @_blink
  127.         @_blink_count = (@_blink_count + 1) % 32
  128.         if @_blink_count < 16
  129.           alpha = (16 - @_blink_count) * 6
  130.         else
  131.           alpha = (@_blink_count - 16) * 6
  132.         end
  133.         self.color.set(255, 255, 255, alpha)
  134.       end
  135.       @@_animations.clear
  136.     end
  137.  
  138.     def update_animation(anime)
  139.       if anime[2] > 0
  140.         frame_index = anime[0].frame_max - anime[2]
  141.         cell_data = anime[0].frames[frame_index].cell_data
  142.         position = anime[0].position
  143.         animation_set_sprites(anime[3], cell_data, position)
  144.         for timing in anime[0].timings
  145.           if timing.frame == frame_index
  146.             animation_process_timing(timing, anime[1])
  147.           end
  148.         end
  149.       else
  150.         @@_reference_count[anime[3][0].bitmap] -= 1
  151.         if @@_reference_count[anime[3][0].bitmap] == 0
  152.             anime[3][0].bitmap.dispose
  153.         end
  154.         for sprite in anime[3]
  155.           sprite.dispose
  156.         end
  157.         @_animation.delete(anime)
  158.       end
  159.     end
  160.     def animation_set_sprites(sprites, cell_data, position)
  161.       for i in 0..15
  162.         sprite = sprites[i]
  163.         pattern = cell_data[i, 0]
  164.         if sprite == nil or pattern == nil or pattern == -1
  165.           sprite.visible = false if sprite != nil
  166.           next
  167.         end
  168.         sprite.visible = true
  169.         sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
  170.         if position == 3
  171.           if self.viewport != nil
  172.             sprite.x = self.viewport.rect.width / 2
  173.             if $game_temp.in_battle and self.battler.is_a?(Game_Enemy)
  174.               sprite.y = self.viewport.rect.height - 320
  175.             else
  176.               sprite.y = self.viewport.rect.height - 160
  177.             end
  178.           else
  179.             sprite.x = 0#320
  180.             sprite.y = 0#240
  181.             #sprite.z = #9999
  182.           end
  183.         else
  184.           sprite.x = self.x + self.viewport.rect.x -
  185.                       self.ox + self.src_rect.width / 2
  186.           if $game_temp.in_battle and self.battler.is_a?(Game_Enemy)
  187.             sprite.y = self.y - self.oy * self.zoom_y / 2 +
  188.                         self.viewport.rect.y
  189.             if position == 0
  190.               sprite.y -= self.src_rect.height * self.zoom_y / 4  
  191.             elsif position == 2
  192.               sprite.y += self.src_rect.height * self.zoom_y / 4  
  193.             end
  194.           else
  195.             sprite.y = self.y + self.viewport.rect.y -
  196.                         self.oy + self.src_rect.height / 2
  197.             sprite.y -= self.src_rect.height / 4 if position == 0
  198.             sprite.y += self.src_rect.height / 4 if position == 2
  199.           end
  200.         end
  201.         sprite.x += cell_data[i, 1]  
  202.         sprite.y += cell_data[i, 2]
  203.         sprite.z = 2000
  204.         sprite.ox = 96
  205.         sprite.oy = 96
  206.         sprite.zoom_x = cell_data[i, 3] / 100.0
  207.         sprite.zoom_y = cell_data[i, 3] / 100.0
  208.         if position != 3
  209.           sprite.zoom_x *= self.zoom_x
  210.           sprite.zoom_y *= self.zoom_y
  211.         end
  212.         sprite.angle = cell_data[i, 4]
  213.         sprite.mirror = (cell_data[i, 5] == 1)
  214.         sprite.opacity = cell_data[i, 6]  #/ 255.0  #* self.opacity
  215.         sprite.blend_type = cell_data[i, 7]
  216.       end
  217.     end
  218.   end
  219. end

点评

切换场景,动画释放,不会被中途保存。如果要保存那也可以实现,就是非常麻烦。为了一点不和谐来做非常麻烦的事,性价比不合算。  发表于 2015-7-11 20:43
在内存有限的时光里, 容纳未见的可能。

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
2
发表于 2015-7-11 20:46:16 | 只看该作者
本帖最后由 恐惧剑刃 于 2015-7-11 20:48 编辑

----------------------------------------------------
搜索
@spriteset = Spriteset_Map.new
改为
$spriteset = Spriteset_Map.new if $spriteset.nil?
----------------------------------------------------
搜索
@spriteset.dispose  并且删除
----------------------------------------------------
搜索
@spriteset.update
改为 $spriteset.update
----------------------------------------------------

不主动释放地图活动块,除非
$spriteset.dispose
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
176
在线时间
359 小时
注册时间
2015-3-29
帖子
125
3
 楼主| 发表于 2015-7-11 21:15:12 | 只看该作者
恐惧剑刃 发表于 2015-7-11 20:46
----------------------------------------------------
搜索
@spriteset = Spriteset_Map.new

提取事件强化的第114行报错 未定义方法 refresh_event .

提取事件强化脚本:
  1. #==============================================================================
  2. # ☆★☆ 提取放置物脚本(强化) ☆★☆  
  3. #------------------------------------------------------------------------------
  4. # - 美兽
  5. # - 2007.4.12
  6. #------------------------------------------------------------------------------
  7. #  爱护环境,人人有责,现实中切勿乱丢垃圾。
  8. #------------------------------------------------------------------------------
  9. #------------------------------------------------------------------------------
  10. #  脚本原理:
  11. #  是从仓库地图中提取事件,将其拷贝放入指定的位置,
  12. #  依此达成随时随地生成新事件的功能,如此可节省大量用RGSS编写事件所消耗的体力,很多地方写的
  13. #  很保守,尽量减少冲突几率。。
  14. #  此为强化版,可实现新事件的保存,但代价是冲突的随之增大,若只想单纯实现ARPG
  15. #  一类的物品掉落,场所移动后便清除,请使用简洁版。
  16. #------------------------------------------------------------------------------
  17. =begin
  18.                                 Note:
  19.   
  20. 一:生成物品主方法:
  21.     Drop_Item.make_events(map_id,event_id,item_x,item_y,save=false)
  22.     map_id : 仓库地图的ID。
  23.     event_id : 仓库中对应事件的ID。
  24.     item_x、item_y :新事件的X与Y坐标
  25.     save : 是否存储标志;
  26.            默认为false,即不存储,场所移动等转换场景后事件会消失;
  27.            true 为存储,取档、关机、登火星,返回后事件仍存在。
  28.            
  29. 二:删除事件方法:
  30.     事件名若包含"delete"字段,则执行完毕会立即自我清除;
  31.     注:任何事件皆如此。

  32. 三:必掌握语句:
  33.     $game_map.events[@event_id]
  34.     $game_player
  35.     事件的脚本使用,表示“本事件”和“角色”,主要为取得事件的坐标,
  36.     取得“本事件”X与Y坐标:$game_map.events[@event_id].event.x
  37.                             $game_map.events[@event_id].event.y
  38.     取得“角色”X与Y坐标:$game_player.x
  39.                           $game_player.y                           
  40.     例如,在某事件左侧生成2号地图的2号事件并永久存储,写法如下。
  41.     x = $game_map.events[@event_id].event.x
  42.     y = $game_map.events[@event_id].event.y
  43.     Drop_Item.make_events(2,2,x-1,y,true)

  44. 四:备注:
  45.     此脚本用法十分灵活,种植、建设、舍弃、掉宝等功能都可用以达成。   

  46. =end
  47. #==============================================================================


  48. module Drop_Item
  49.   
  50.   def self.make_events(map_id,event_id,item_x,item_y,save=false)
  51.       return unless self.is_map?        
  52.       map = self.map_data_load(map_id)      
  53.       temp = Marshal.load(Marshal.dump(map))      
  54.       if !$game_system.map_events_number
  55.          $game_system.map_events_number = {}
  56.       end  
  57.       sum = $game_system.map_events_number      
  58.       m_id = $game_map.map_id      
  59.       sum[m_id] == nil ? sum[m_id] = 2000 : sum[m_id] += 1
  60.       new_event_id = sum[m_id]      
  61.       temp.events[event_id].id = new_event_id      
  62.       temp.events[event_id].x,temp.events[event_id].y = item_x,item_y      
  63.       $game_map.events[new_event_id] = Game_Event.new(m_id,temp.events[event_id])
  64.       if save
  65.          now_map = self.map_data_load(m_id)
  66.          now_map.events[new_event_id] = temp.events[event_id]
  67.          self.map_data_save(m_id,now_map)
  68.       end  
  69.        refresh_map(new_event_id)
  70.   end
  71.    
  72.   def self.map_data_init   
  73.       for i in 1..999
  74.          begin
  75.            map = load_data(sprintf("Data/Map%03d.rxdata", i))
  76.          rescue Errno::ENOENT
  77.            next
  78.          end
  79.          $game_system.map_data[i] = Marshal.load(Marshal.dump(map))         
  80.       end
  81.   end  
  82.   
  83.   def self.map_data_save(map_id,event)
  84.       $game_system.map_data[$game_map.map_id] = event           
  85.   end   

  86.   def self.map_data_load(map_id)
  87.       if !$game_system.map_data
  88.          $game_system.map_data = {}
  89.          self.map_data_init
  90.       end
  91.       return $game_system.map_data[map_id]      
  92.   end  
  93.    
  94.   def self.delete_events(event_id)
  95.       return unless self.is_map?     
  96.       $game_map.events.delete(event_id)
  97.    #   self.refresh_map
  98.   end
  99.    
  100.   def self.refresh_map
  101.       return unless self.is_map?
  102.       $scene.spriteset.dispose
  103.       $scene.spriteset = Spriteset_Map.new   
  104.     end
  105.    
  106.   def self.refresh_map(i)
  107.     return unless self.is_map?
  108.     $scene.spriteset.refresh_events(i)  
  109.   end   
  110.   
  111.   def self.is_map?
  112.       (return true) if $scene.is_a?(Scene_Map)
  113.       return false
  114.   end

  115. end  

  116. class Game_Map
  117.   
  118.   def setup(map_id)
  119.       @map_id = map_id  
  120.       #@map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
  121.       @map = Drop_Item.map_data_load(@map_id)
  122.       tileset = $data_tilesets[@map.tileset_id]
  123.       @tileset_name = tileset.tileset_name
  124.       @autotile_names = tileset.autotile_names
  125.       @panorama_name = tileset.panorama_name
  126.       @panorama_hue = tileset.panorama_hue
  127.       @fog_name = tileset.fog_name
  128.       @fog_hue = tileset.fog_hue
  129.       @fog_opacity = tileset.fog_opacity
  130.       @fog_blend_type = tileset.fog_blend_type
  131.       @fog_zoom = tileset.fog_zoom
  132.       @fog_sx = tileset.fog_sx
  133.       @fog_sy = tileset.fog_sy
  134.       @battleback_name = tileset.battleback_name
  135.       @passages = tileset.passages
  136.       @priorities = tileset.priorities
  137.       @terrain_tags = tileset.terrain_tags
  138.       @display_x = 0
  139.       @display_y = 0
  140.       @need_refresh = false
  141.       @events = {}
  142.       for i in @map.events.keys
  143.         @events[i] = Game_Event.new(@map_id, @map.events[i])
  144.       end
  145.       @common_events = {}
  146.       for i in 1...$data_common_events.size
  147.         @common_events[i] = Game_CommonEvent.new(i)
  148.       end
  149.       @fog_ox = 0
  150.       @fog_oy = 0
  151.       @fog_tone = Tone.new(0, 0, 0, 0)
  152.       @fog_tone_target = Tone.new(0, 0, 0, 0)
  153.       @fog_tone_duration = 0
  154.       @fog_opacity_duration = 0
  155.       @fog_opacity_target = 0
  156.       @scroll_direction = 2
  157.       @scroll_rest = 0
  158.       @scroll_speed = 4
  159.   end
  160.    
  161. end

  162. class Interpreter
  163.   
  164.   def command_end
  165.       @list = nil
  166.       if @main and @event_id > 0
  167.          if $game_map.events[@event_id].event.name[/delete/].nil?
  168.             $game_map.events[@event_id].unlock            
  169.          else
  170.             if $scene.is_a?(Scene_Map)
  171.                Drop_Item.delete_events(@event_id)
  172.                now_map = Drop_Item.map_data_load($game_map.map_id)
  173.                now_map.events.delete(@event_id)
  174.                Drop_Item.map_data_save($game_map.map_id,now_map)              
  175.             end         
  176.          end         
  177.       end
  178.   end
  179.    
  180. end

  181. class Game_System
  182.   
  183.   attr_accessor :map_events_number            
  184.   attr_accessor :map_data            
  185.    
  186. end  

  187. class Scene_Map
  188.   
  189.   attr_accessor :spriteset            
  190.   
  191. end  
  192. class Spriteset_Map
  193.   def refresh_events(i)
  194.     sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
  195.     @character_sprites.push(sprite)
  196.   end
  197. end
复制代码
在内存有限的时光里, 容纳未见的可能。
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-17 03:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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