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

Project1

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

[已经解决] 做了一个让地图居中的脚本,有问题!

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
41 小时
注册时间
2010-7-10
帖子
111
跳转到指定楼层
1
发表于 2012-4-3 17:23:00 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 zhangchi5 于 2012-4-8 17:24 编辑

地图居中没有出问题
里面有一部分是让事件可以在循环的地图里显示多个的,出了问题。

本来上面有一个,下面也有一个,结果只有一个了。。。

以解决。。。Event要Clone...

脚本:


  1. $V_Height=0
  2. $V_Width=0

  3. $All_Width=640
  4. $All_Height=480

  5. #==============================================================================
  6. # ■ Game_CharacterBase
  7. #------------------------------------------------------------------------------
  8. #  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。
  9. #==============================================================================

  10. class Game_CharacterBase
  11.   attr_accessor   :px                        # 地图 X 坐标偏移
  12.   attr_accessor   :py                        # 地图 Y 坐标偏移
  13.   
  14.   #--------------------------------------------------------------------------
  15.   # ● 初始化公有成员变量
  16.   #--------------------------------------------------------------------------
  17.   def init_public_members
  18.     @id = 0
  19.     @x = 0
  20.     @y = 0
  21.     @real_x = 0
  22.     @real_y = 0
  23.     @tile_id = 0
  24.     @character_name = ""
  25.     @character_index = 0
  26.     @move_speed = 4
  27.     @move_frequency = 6
  28.     @walk_anime = true
  29.     @step_anime = false
  30.     @direction_fix = false
  31.     @opacity = 255
  32.     @blend_type = 0
  33.     @direction = 2
  34.     @pattern = 1
  35.     @priority_type = 1
  36.     @through = false
  37.     @bush_depth = 0
  38.     @animation_id = 0
  39.     @balloon_id = 0
  40.     @transparent = false
  41.     @px = 0
  42.     @py = 0
  43.   end

  44.   #--------------------------------------------------------------------------
  45.   # ● 获取画面 X 坐标
  46.   #--------------------------------------------------------------------------
  47.   def screen_x
  48.     $game_map.adjust_x(@real_x) * 32 + 16 + @px
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 获取画面 Y 坐标
  52.   #--------------------------------------------------------------------------
  53.   def screen_y
  54.     $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height + @py
  55.   end
  56. end

  57. #==============================================================================
  58. # ■ Scene_Map
  59. #------------------------------------------------------------------------------
  60. #  地图画面
  61. #==============================================================================

  62. class Scene_Map < Scene_Base
  63.   #--------------------------------------------------------------------------
  64.   # ● 开始处理
  65.   #--------------------------------------------------------------------------
  66.   def start
  67.     super
  68.     SceneManager.clear
  69.     $game_player.straighten
  70.     $game_map.refresh
  71.     $game_message.visible = false
  72.     create_spriteset
  73.     create_all_windows
  74.     @menu_calling = false
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● 场所移动后的处理
  78.   #--------------------------------------------------------------------------
  79.   def post_transfer
  80.     @spriteset.refresh_viewports
  81.    
  82.     case $game_temp.fade_type
  83.     when 0
  84.       Graphics.wait(fadein_speed / 2)
  85.       fadein(fadein_speed)
  86.     when 1
  87.       Graphics.wait(fadein_speed / 2)
  88.       white_fadein(fadein_speed)
  89.     end
  90.     @map_name_window.open
  91.   end

  92. end

  93. #==============================================================================
  94. # ■ Game_Map
  95. #------------------------------------------------------------------------------
  96. #  管理地图的类。拥有卷动地图以及判断通行度的功能。
  97. #   本类的实例请参考 $game_map 。
  98. #==============================================================================

  99. class Game_Map
  100.   #--------------------------------------------------------------------------
  101.   # ● 设置
  102.   #--------------------------------------------------------------------------
  103.   def setup(map_id)
  104.     @map_id = map_id
  105.     @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
  106.    
  107.     init_V
  108.    
  109.     @tileset_id = @map.tileset_id
  110.     @display_x = 0
  111.     @display_y = 0
  112.     referesh_vehicles
  113.     setup_events
  114.     setup_scroll
  115.     setup_parallax
  116.     setup_battleback
  117.     @need_refresh = false
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 画面的横向图块数
  121.   #--------------------------------------------------------------------------
  122.   def screen_tile_x
  123.     $V_Width / 32
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 画面的纵向图块数
  127.   #--------------------------------------------------------------------------
  128.   def screen_tile_y
  129.     $V_Height / 32
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 刷新
  133.   #--------------------------------------------------------------------------
  134.   def refresh
  135.     @events.each_value {|event| event.refresh }
  136.     @common_events.each {|event| event.refresh }
  137.     refresh_tile_events
  138.     @need_refresh = false
  139.   end

  140.   
  141.   def init_V
  142.     $V_Width=width*32
  143.     $V_Height=height*32
  144.     if $V_Width>=$All_Width || loop_horizontal? then
  145.       $V_Width=$All_Width
  146.     end
  147.     if $V_Height>=$All_Height || loop_vertical? then
  148.       $V_Height=$All_Height
  149.     end
  150.   end

  151.   #--------------------------------------------------------------------------
  152.   # ● 计算显示坐标的剩余 X 坐标
  153.   #--------------------------------------------------------------------------
  154.   def adjust_x(x)
  155.     if $game_map.loop_horizontal? && x < @display_x - (width - screen_tile_x) / 2
  156.       x - @display_x + @map.width
  157.     else
  158.       x - @display_x
  159.     end
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● 计算显示坐标的剩余 Y 坐标
  163.   #--------------------------------------------------------------------------
  164.   def adjust_y(y)
  165.     if $game_map.loop_vertical? && y < @display_y - (height - screen_tile_y) / 2
  166.       y - @display_y + @map.height
  167.     else
  168.       y - @display_y
  169.     end
  170.   end

  171. end

  172. #==============================================================================
  173. # ■ Spriteset_Map
  174. #------------------------------------------------------------------------------
  175. #  处理地图画面精灵和图块的类。本类在 Scene_Map 类的内部使用。
  176. #==============================================================================

  177. class Spriteset_Map
  178.   #--------------------------------------------------------------------------
  179.   # ● 生成显示端口
  180.   #--------------------------------------------------------------------------
  181.   def create_viewports
  182.     x=(Graphics.width-$V_Width)/2
  183.     y=(Graphics.height-$V_Height)/2
  184.     @viewport1 = Viewport.new(x,y,$V_Width,$V_Height)
  185.     @viewport2 = Viewport.new(x,y,$V_Width,$V_Height)
  186.     @viewport3 = Viewport.new(x,y,$V_Width,$V_Height)
  187.     @viewport2.z = 50
  188.     @viewport3.z = 100
  189.   end
  190.   
  191.   def refresh_viewports
  192.     x=(Graphics.width-$V_Width)/2
  193.     y=(Graphics.height-$V_Height)/2
  194.     @V_rect=Rect.new(x,y,$V_Width,$V_Height)
  195.     @viewport1.rect=@V_rect
  196.     @viewport2.rect=@V_rect
  197.     @viewport3.rect=@V_rect
  198.     @viewport2.z = 50
  199.     @viewport3.z = 100
  200.   end
  201.   
  202.   #--------------------------------------------------------------------------
  203.   # ● 生成人物精灵
  204.   #--------------------------------------------------------------------------
  205.   def create_characters
  206.     @character_sprites = []
  207.    
  208.     $game_map.events.values.each do |event|
  209.       if $game_map.width*32<$All_Width then
  210.         if $game_map.loop_horizontal? then
  211.           @sc=Sprite_Character.new(@viewport1, event)
  212.           @sc.character.px=-$game_map.width*32
  213.           @character_sprites.push(@sc)
  214.          
  215.           @sc=Sprite_Character.new(@viewport1, event)
  216.           @sc.character.px=$game_map.width*32
  217.           @character_sprites.push(@sc)
  218.         end
  219.       end
  220.       
  221.       if $game_map.height*32<$All_Height then
  222.         if $game_map.loop_vertical? then
  223.           @sc=Sprite_Character.new(@viewport1, event)
  224.           @sc.character.py=-$game_map.height*32
  225.           @character_sprites.push(@sc)
  226.          
  227.           @sc=Sprite_Character.new(@viewport1, event)
  228.           @sc.character.py=$game_map.height*32
  229.           @character_sprites.push(@sc)
  230.         end
  231.       end
  232.       
  233.       if $game_map.height*32<$All_Height || $game_map.width*32<$All_Width then
  234.         if $game_map.loop_horizontal? && $game_map.loop_vertical? then
  235.           @sc=Sprite_Character.new(@viewport1, event)
  236.           @sc.character.px=-$game_map.width*32
  237.           @sc.character.py=-$game_map.height*32
  238.           @character_sprites.push(@sc)
  239.          
  240.           @sc=Sprite_Character.new(@viewport1, event)
  241.           @sc.character.px=$game_map.width*32
  242.           @sc.character.py=-$game_map.height*32
  243.           @character_sprites.push(@sc)   
  244.          
  245.           @sc=Sprite_Character.new(@viewport1, event)
  246.           @sc.character.px=-$game_map.width*32
  247.           @sc.character.py=$game_map.height*32
  248.           @character_sprites.push(@sc)
  249.          
  250.           @sc=Sprite_Character.new(@viewport1, event)
  251.           @sc.character.px=$game_map.width*32
  252.           @sc.character.py=$game_map.height*32
  253.           @character_sprites.push(@sc)
  254.         end
  255.       end
  256.       @character_sprites.push(Sprite_Character.new(@viewport1, event))
  257.       
  258.     end
  259.     $game_map.vehicles.each do |vehicle|
  260.       @character_sprites.push(Sprite_Character.new(@viewport1, vehicle))
  261.     end
  262.     $game_player.followers.reverse_each do |follower|
  263.       @character_sprites.push(Sprite_Character.new(@viewport1, follower))
  264.     end
  265.     @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  266.     @map_id = $game_map.map_id
  267.   end

  268. end

  269. #==============================================================================
  270. # ■ Game_Player
  271. #------------------------------------------------------------------------------
  272. #  处理玩家人物的类。拥有事件启动的判定、地图的卷动等功能。
  273. #   本类的实例请参考 $game_player 。
  274. #==============================================================================

  275. class Game_Player < Game_Character
  276.   #--------------------------------------------------------------------------
  277.   # ● 执行场所移动
  278.   #--------------------------------------------------------------------------
  279.   def perform_transfer
  280.     if transfer?
  281.       set_direction(@new_direction)
  282.       if @new_map_id != $game_map.map_id
  283.         $game_map.setup(@new_map_id)
  284.         $game_map.autoplay
  285.       end
  286.       moveto(@new_x, @new_y)
  287.       clear_transfer_info
  288.     end
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # ● 画面中央的 X 坐标
  292.   #--------------------------------------------------------------------------
  293.   def center_x
  294.     ($V_Width / 32 - 1) / 2.0
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # ● 画面中央的 Y 坐标
  298.   #--------------------------------------------------------------------------
  299.   def center_y
  300.     ($V_Height / 32 - 1) / 2.0
  301.   end
  302. end
复制代码

Lv1.梦旅人

梦石
0
星屑
120
在线时间
176 小时
注册时间
2011-8-7
帖子
1032
2
发表于 2012-4-7 19:20:55 | 只看该作者
还可以的脚本。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-13 21:47

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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