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

Project1

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

[已经解决] 人物跟随出错

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
跳转到指定楼层
1
发表于 2022-7-13 11:11:15 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 黑米馒头 于 2022-7-27 17:10 编辑

RGU了之后,人物跟随脚本出错





大佬说这里需要判断@move_list是否为nil,有大神知道怎么弄吗。。。


人物跟随

RUBY 代码复制
  1. module Train_Actor
  2.  
  3. # 是否使用停止跟随的方法,也就是说,这里false改为true的时候,
  4. # 如果 TRANSPARENT_SWITCHES_INDEX
  5.  
  6. # 开关打开,跟随的人物就消失了(其实只是变成透明而已)
  7.  
  8. # 开关
  9. TRANSPARENT_SWITCH = true
  10. # 开关编号
  11. TRANSPARENT_SWITCHES_INDEX = 3
  12.  
  13. # 举例:第一个为true,第二个为3,则打开3号开关,后面的人都没了。
  14.  
  15. # 跟随人数的最大数目,可以更改为2、3、4什么的。
  16.  
  17. TRAIN_ACTOR_SIZE_MAX = 4
  18.  
  19.  
  20. # 跟随距离,例如0为紧贴,1为分开一个身位
  21.  
  22. TRAIN_ACTOR_DISTANCE = 1
  23. # 定数
  24. #Input::DOWN = 2
  25. #Input::LEFT = 4
  26. #Input::RIGHT = 6
  27. #Input::UP = 8
  28. DOWN_LEFT = 1
  29. DOWN_RIGHT = 3
  30. UP_LEFT = 7
  31. UP_RIGHT = 9
  32. JUMP = 5
  33.  
  34. # 插入空角色,造成分开一段距离跟随的假象
  35. TRAIN_ACTOR_SIZE_MAX = TRAIN_ACTOR_SIZE_MAX * (TRAIN_ACTOR_DISTANCE+1) + 1
  36.  
  37. #==============================================================================
  38. # ■ Game_Party_Actor
  39. #------------------------------------------------------------------------------
  40. # 
  41. #==============================================================================
  42. class Game_Party_Actor < Game_Character
  43. attr_reader  :name, :stop_name, :appellation, :name_color, :character_hue
  44. def initialize
  45.    super()
  46.    @name = ""
  47.    @appellation = ""
  48.    @name_color = 0
  49.    @through = true
  50.    @save = false
  51.    @character_hue
  52. end
  53. def setup(actor)
  54.    @actor = actor
  55.    # 设定角色的文件名和色调
  56.    if actor != nil
  57.      @name = actor.name
  58.      @appellation = actor.appellation
  59.      @name_color = actor.name_color
  60.      @character_name = actor.character_name
  61.      @character_hue = actor.character_hue
  62.      @character_hue = actor.battler_hue
  63.    else
  64.      @character_name = ""
  65.      @character_hue = 0
  66.      @name = @appellation = ""
  67.    end
  68.    # 初始化不透明度和合成方法
  69.    @opacity = 255
  70.    @blend_type = 0
  71. end
  72. def screen_z(height = 0)
  73.    if $game_player.x == @x and $game_player.y == @y
  74.     return $game_player.screen_z(height) - 1
  75.    end
  76.    super(height)
  77. end
  78. attr_writer :move_speed
  79. attr_writer :step_anime
  80. end
  81.  
  82. #==============================================================================
  83. # ■ Spriteset_Map_Module
  84. #------------------------------------------------------------------------------
  85. #  
  86. #==============================================================================
  87. module Spriteset_Map_Module
  88. def setup_actor_character_sprites?
  89.    return @setup_actor_character_sprites_flag != nil
  90. end
  91. def setup_actor_character_sprites(characters)
  92.    if !setup_actor_character_sprites?
  93.      index_game_player = 0
  94.      @character_sprites.each_index do |i|
  95.        if @character_sprites[i].character.instance_of?(Game_Player)
  96.          index_game_player = i
  97.          break
  98.        end
  99.    end
  100.    for character in characters.reverse
  101.      @character_sprites.unshift(
  102.        Sprite_Character.new(@viewport1, character)
  103.        )
  104.    end
  105.    @setup_actor_character_sprites_flag = true
  106.   end
  107. end
  108. end
  109.  
  110. #==============================================================================
  111. # ■ Scene_Map_Module
  112. #------------------------------------------------------------------------------
  113. #  
  114. #==============================================================================
  115. module Scene_Map_Module
  116. def setup_actor_character_sprites(characters)
  117.   $spriteset.setup_actor_character_sprites(characters)
  118. end
  119. end
  120.  
  121. #==============================================================================
  122. # ■ Game_Party_Module
  123. #------------------------------------------------------------------------------
  124. #  
  125. #==============================================================================
  126. module Game_Party_Module
  127. def set_transparent_actors(transparent)
  128.    @transparent = transparent
  129. end
  130. def setup_actor_character_sprites
  131.    if @characters.nil?
  132.      @characters = []
  133.      for i in 1 ...  TRAIN_ACTOR_SIZE_MAX
  134.        @characters.push(Game_Party_Actor.new)
  135.      end
  136.    end
  137. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  138.   if i % (TRAIN_ACTOR_DISTANCE+1) == 0
  139.     @characters[i-1].setup(actors[i/(TRAIN_ACTOR_DISTANCE+1)])
  140.   end
  141. end
  142.   if $scene.class.method_defined?('setup_actor_character_sprites')
  143.     $scene.setup_actor_character_sprites(@characters)
  144.   end
  145. end
  146. def update_party_actors
  147.    setup_actor_character_sprites
  148.    transparent = $game_player.transparent
  149.   if transparent == false
  150.     if TRANSPARENT_SWITCH
  151.       transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  152.     end
  153.   end
  154.   for character in @characters
  155.     character.transparent = transparent
  156.     character.move_speed = $game_player.move_speed
  157.     character.update
  158.   end
  159. end
  160. def moveto_party_actors( x, y )
  161.    setup_actor_character_sprites
  162.    for character in @characters
  163.      character.moveto( x, y )
  164.    end
  165.    if @move_list == nil
  166.      @move_list = []
  167.    end
  168.    move_list_setup
  169. end
  170. def move_party_actors
  171.   if @move_list == nil
  172.     @move_list = []
  173.     move_list_setup
  174.   end
  175.  
  176. def move_list_setup
  177.   for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  178.     @move_list[i] = nil
  179.   end
  180. end  
  181.  
  182.   @move_list.each_index do |i|
  183.   if @characters[i] != nil
  184.     case @move_list[i].type
  185.     when Input::DOWN
  186.       @characters[i].move_down(@move_list[i].args[0])
  187.     when Input::LEFT
  188.       @characters[i].move_left(@move_list[i].args[0])
  189.     when Input::RIGHT
  190.       @characters[i].move_right(@move_list[i].args[0])
  191.     when Input::UP
  192.       @characters[i].move_up(@move_list[i].args[0])
  193.     when DOWN_LEFT
  194.       @characters[i].move_lower_left
  195.     when DOWN_RIGHT
  196.       @characters[i].move_lower_right
  197.     when UP_LEFT
  198.       @characters[i].move_upper_left
  199.     when UP_RIGHT
  200.       @characters[i].move_upper_right
  201.     when JUMP
  202.       @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  203.     end
  204.   end
  205. end
  206. end
  207.  
  208. #==============================================================================
  209. # ■ Move_List_Element
  210. #------------------------------------------------------------------------------
  211. #  
  212. #==============================================================================
  213. class Move_List_Element
  214.   def initialize(type,args)
  215.     @type = type
  216.     @args = args
  217.   end
  218.   def type()
  219.     return @type
  220.   end
  221.   def args()
  222.     return @args
  223.   end
  224. end
  225. def move_list_setup
  226.   for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  227.     @move_list[i] = nil
  228.   end
  229. end
  230. def add_move_list(type,*args)
  231.   @move_list.unshift(Move_List_Element.new(type,args)).pop
  232. end
  233. def move_down_party_actors(turn_enabled = true)
  234.   move_party_actors
  235.   add_move_list(Input::DOWN,turn_enabled)
  236. end
  237. def move_left_party_actors(turn_enabled = true)
  238.   move_party_actors
  239.   add_move_list(Input::LEFT,turn_enabled)
  240. end
  241. def move_right_party_actors(turn_enabled = true)
  242.   move_party_actors
  243.   add_move_list(Input::RIGHT,turn_enabled)
  244. end
  245. def move_up_party_actors(turn_enabled = true)
  246.   move_party_actors
  247.   add_move_list(Input::UP,turn_enabled)
  248. end
  249. def move_lower_left_party_actors
  250.   move_party_actors
  251.   add_move_list(DOWN_LEFT)
  252. end
  253. def move_lower_right_party_actors
  254.   move_party_actors
  255.   add_move_list(DOWN_RIGHT)
  256. end
  257. def move_upper_left_party_actors
  258.   move_party_actors
  259.   add_move_list(UP_LEFT)
  260. end
  261. def move_upper_right_party_actors
  262.   move_party_actors
  263.   add_move_list(UP_RIGHT)
  264. end
  265. def jump_party_actors(x_plus, y_plus)
  266.   move_party_actors
  267.   add_move_list(JUMP,x_plus, y_plus)
  268. end
  269. end
  270. module Game_Player_Module
  271. def update
  272.   $game_party.update_party_actors
  273.   super
  274. end
  275. def moveto( x, y )
  276.   $game_party.moveto_party_actors( x, y )
  277.   super( x, y )
  278. end
  279. def move_down(turn_enabled = true)
  280.   if passable?(@x, @y, Input::DOWN)
  281.     $game_party.move_down_party_actors(turn_enabled)
  282.   #..........................................................................
  283.   elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN) and
  284.         can_go?(@x, @y + 1)
  285.     @direction = 1
  286.     $game_party.move_lower_left_party_actors
  287.     increase_steps
  288.   elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN) and
  289.         can_go?(@x, @y + 1)
  290.     @direction = 3
  291.     $game_party.move_lower_right_party_actors
  292.     increase_steps
  293.   #..........................................................................
  294.   end
  295.   super(turn_enabled)
  296. end
  297. def move_left(turn_enabled = true)
  298.   if passable?(@x, @y, Input::LEFT)
  299.     $game_party.move_left_party_actors(turn_enabled)
  300.   #..........................................................................
  301.   elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT) and
  302.         can_go?(@x - 1, @y)
  303.     @direction = 7
  304.     $game_party.move_upper_left_party_actors
  305.     increase_steps
  306.   elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT) and
  307.         can_go?(@x - 1, @y)
  308.     @direction = 1
  309.     $game_party.move_lower_left_party_actors
  310.     increase_steps
  311.   #..........................................................................
  312.   end
  313.   super(turn_enabled)
  314. end
  315. def move_right(turn_enabled = true)
  316.   if passable?(@x, @y, Input::RIGHT)
  317.     $game_party.move_right_party_actors(turn_enabled)
  318.   #..........................................................................
  319.   elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT) and
  320.         can_go?(@x + 1, @y)
  321.     @direction = 9
  322.     $game_party.move_upper_right_party_actors
  323.     increase_steps
  324.   elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT) and
  325.         can_go?(@x + 1, @y)
  326.     @direction = 3
  327.     $game_party.move_lower_right_party_actors
  328.     increase_steps
  329.   #..........................................................................
  330.   end
  331.   super(turn_enabled)
  332. end
  333. def move_up(turn_enabled = true)
  334.   if passable?(@x, @y, Input::UP)
  335.     $game_party.move_up_party_actors(turn_enabled)
  336.   #..........................................................................
  337.   elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP) and
  338.         can_go?(@x, @y - 1)
  339.     @direction = 7
  340.     $game_party.move_upper_left_party_actors
  341.     increase_steps
  342.   elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP) and
  343.         can_go?(@x, @y - 1)
  344.     @direction = 9
  345.     $game_party.move_upper_right_party_actors
  346.     increase_steps
  347.   #..........................................................................
  348.   end
  349.   super(turn_enabled)
  350. end
  351. def move_lower_left
  352.   # 下→左、左→下 のどちらかのコースが通行可能な場合
  353.   @direction = 1
  354.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  355.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  356.     $game_party.move_lower_left_party_actors
  357.     increase_steps
  358.   #..........................................................................
  359.   elsif passable?(@x, @y, Input::DOWN) and can_go?(@x - 1, @y + 1)
  360.     $game_party.move_down_party_actors
  361.     @direction = 2
  362.     increase_steps
  363.   elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y + 1)
  364.     $game_party.move_left_party_actors
  365.     @direction = 4
  366.     increase_steps
  367.   #..........................................................................
  368.   end
  369.   super
  370. end
  371. def move_lower_right
  372.   # 下→右、右→下 のどちらかのコースが通行可能な場合
  373.   @direction = 3
  374.   if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  375.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  376.     $game_party.move_lower_right_party_actors
  377.     increase_steps
  378.   #..........................................................................
  379.   elsif passable?(@x, @y, Input::DOWN) and can_go?(@x + 1, @y + 1)
  380.     $game_party.move_down_party_actors
  381.     @direction = 2
  382.     increase_steps
  383.   elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y + 1)
  384.     $game_party.move_right_party_actors
  385.     @direction = 6
  386.     increase_steps
  387.   #..........................................................................
  388.   end
  389.   super
  390. end
  391. def move_upper_left
  392.   # 上→左、左→上 のどちらかのコースが通行可能な場合
  393.   @direction = 7
  394.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  395.      (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  396.     $game_party.move_upper_left_party_actors
  397.     increase_steps
  398.   #..........................................................................
  399.   elsif passable?(@x, @y, Input::UP) and can_go?(@x - 1, @y - 1)
  400.     $game_party.move_up_party_actors
  401.     @direction = 8
  402.     increase_steps
  403.   elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y - 1)
  404.     $game_party.move_left_party_actors
  405.     @direction = 4
  406.     increase_steps
  407.   #..........................................................................
  408.   end
  409.   super
  410. end
  411. def move_upper_right
  412.   # 上→右、右→上 のどちらかのコースが通行可能な場合
  413.   @direction = 9
  414.   if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  415.      (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  416.     $game_party.move_upper_right_party_actors
  417.     increase_steps
  418.   #..........................................................................
  419.   elsif passable?(@x, @y, Input::UP) and can_go?(@x + 1, @y - 1)
  420.     $game_party.move_up_party_actors
  421.     @direction = 8
  422.     increase_steps
  423.   elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y - 1)
  424.     $game_party.move_right_party_actors
  425.     @direction = 6
  426.     increase_steps
  427.   #..........................................................................
  428.   end
  429.   super
  430. end
  431. def jump(x_plus, y_plus)
  432.   # 新しい座標を計算
  433.   new_x = @x + x_plus
  434.   new_y = @y + y_plus
  435.   # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  436.   if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  437.     $game_party.jump_party_actors(x_plus, y_plus)
  438.   end
  439.   super(x_plus, y_plus)
  440. end
  441. attr_reader :move_speed
  442. attr_reader :step_anime
  443. end
  444. end # module Train_Actor
  445.  
  446. #==============================================================================
  447. # ■ Game_Party
  448. #------------------------------------------------------------------------------
  449. #  处理同伴的类。包含金钱以及物品的信息。本类的实例
  450. # 请参考 $game_party。
  451. #==============================================================================
  452. class Game_Party
  453.   include Train_Actor::Game_Party_Module
  454. end
  455.  
  456. #==============================================================================
  457. # ■ Game_Player
  458. #------------------------------------------------------------------------------
  459. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  460. # 本类的实例请参考 $game_player。
  461. #==============================================================================
  462. class Game_Player
  463.   include Train_Actor::Game_Player_Module
  464. end
  465.  
  466. #==============================================================================
  467. # ■ Spriteset_Map
  468. #------------------------------------------------------------------------------
  469. #  处理地图画面活动块和元件的类。本类在
  470. # Scene_Map 类的内部使用。
  471. #==============================================================================
  472. class Spriteset_Map
  473.   include Train_Actor::Spriteset_Map_Module
  474. end
  475.  
  476. #==============================================================================
  477. # ■ Scene_Map
  478. #------------------------------------------------------------------------------
  479. #  处理地图画面的类。
  480. #==============================================================================
  481. class Scene_Map
  482.   include Train_Actor::Scene_Map_Module
  483. end

Lv3.寻梦者

梦石
0
星屑
4481
在线时间
380 小时
注册时间
2012-11-8
帖子
272
2
发表于 2022-7-14 08:56:30 | 只看该作者
本帖最后由 qq634488405 于 2022-7-14 08:58 编辑
  1. if @move_list == nil
  2.     @move_list = []
  3.     move_list_setup
  4. end

  5. def move_list_setup
  6.   for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  7.     @move_list[i] = nil
  8.   end
  9. end
  10. 当@move_list为nil时给@move_list塞一堆nil,然后判断时出错。可能加个判断@move_list[i]是否为nil能解决,但不清楚会不会影响其他功能
复制代码

点评

具体该怎么弄。。。  发表于 2022-7-14 12:46
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7946
在线时间
1182 小时
注册时间
2007-7-29
帖子
2055
3
发表于 2022-7-27 22:59:16 | 只看该作者
和之前情况类似,我只能从代码上来绕过出错提示,无法保证解决问题。话说其实楼上已经给出思路:
  1.   if @characters[i] != nil
复制代码

将出错提示行改成:
  1.   if @characters[i] != nil and @move_list[i] != nil
复制代码

点评

完美解决!感谢  发表于 2022-7-28 21:55
我看行  发表于 2022-7-28 15:15

评分

参与人数 1星屑 +50 收起 理由
RyanBern + 50 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-29 06:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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