| 本帖最后由 asdwds 于 2013-7-14 23:18 编辑 
 lllzjsj 发表于 2013-7-14 19:42 ![]() 问题是我要的是实际在移动,而不是一直向上
 我要做的就是主角不停地向上跑,停不下来 ...
 如果是要让主角一直往某个方向跑的话,可以考虑用我写的。
 使用方法看下楼,有BUG请告诉我
 
 下面第一个是在开关2打开时,玩家将不能上下走。下面第二个是通过设置$game_player.upx和upy从而让其每帧都位移
 
 #==============================================================================# ■ Game_CharacterBase#------------------------------------------------------------------------------#  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。#==============================================================================class Game_CharacterBase  #--------------------------------------------------------------------------  # ● 径向移动  # 用不了alias,所以请注意插入的位置  #--------------------------------------------------------------------------  def move_straight(d, turn_ok = true)    @move_succeed = passable?(@x, @y, d)    if @move_succeed && onlyRL?(d)  #就这里改动了      set_direction(d)      @x = $game_map.round_x_with_direction(@x, d)      @y = $game_map.round_y_with_direction(@y, d)      @real_x = $game_map.x_with_direction(@x, reverse_dir(d))      @real_y = $game_map.y_with_direction(@y, reverse_dir(d))      increase_steps    elsif turn_ok &&      set_direction(d)      check_event_trigger_touch_front    end  end  #--------------------------------------------------------------------------  # ● 判断是否是往左或右移动 并且是只能左右的情况  #   在这里设定的是 $game_switches[2]== true 时是只能左右,  #  随意更改[]内数字,只要记得在限定左右时,开关操作-打开[]开关就可以了  #--------------------------------------------------------------------------  def onlyRL?(d)    if $game_switches[2] == true      if d == 2 or d == 8        return false      end    end    return true  endend
#============================================================================== 
# ■ Game_CharacterBase 
#------------------------------------------------------------------------------ 
#  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。 
#============================================================================== 
class Game_CharacterBase 
  #-------------------------------------------------------------------------- 
  # ● 径向移动 
  # 用不了alias,所以请注意插入的位置 
  #-------------------------------------------------------------------------- 
  def move_straight(d, turn_ok = true) 
    @move_succeed = passable?(@x, @y, d) 
    if @move_succeed && onlyRL?(d)  #就这里改动了 
      set_direction(d) 
      @x = $game_map.round_x_with_direction(@x, d) 
      @y = $game_map.round_y_with_direction(@y, d) 
      @real_x = $game_map.x_with_direction(@x, reverse_dir(d)) 
      @real_y = $game_map.y_with_direction(@y, reverse_dir(d)) 
      increase_steps 
    elsif turn_ok && 
      set_direction(d) 
      check_event_trigger_touch_front 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 判断是否是往左或右移动 并且是只能左右的情况 
  #   在这里设定的是 $game_switches[2]== true 时是只能左右, 
  #  随意更改[]内数字,只要记得在限定左右时,开关操作-打开[]开关就可以了 
  #-------------------------------------------------------------------------- 
  def onlyRL?(d) 
    if $game_switches[2] == true 
      if d == 2 or d == 8 
        return false 
      end 
    end 
    return true 
  end 
end 
 下面第二个是通过设置$game_player.upx和upy从而让其每帧都位移
 
 #==============================================================================# ■ Game_CharacterBase#------------------------------------------------------------------------------#  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。#============================================================================== class Game_Player < Game_Character  #--------------------------------------------------------------------------  # ● 定义实例变量  #--------------------------------------------------------------------------  attr_accessor   :upy                        # y 每帧增长的y  attr_accessor   :upx                        # x 每帧增长的y  attr_accessor   :upover                     # 强制位移终止  #--------------------------------------------------------------------------  # ● 初始化对象  #--------------------------------------------------------------------------  alias init initialize  def initialize    init    @upx = 0    @upy = 0     @upover = false  end  #--------------------------------------------------------------------------  # ● 由方向键移动  #--------------------------------------------------------------------------  def move_by_input    return if !movable? || ($game_map.interpreter.running? and (@upy == 0 and @upx == 0) ) #多加了一个条件   #若觉得条件太长,改成@uping的true/false变量,一旦使用强制移动就打开,不使用就false    move_straight(Input.dir4) if Input.dir4 > 0  end  #--------------------------------------------------------------------------  # ● 更新画面  #  没有使用alias,请注意插入的位置 #--------------------------------------------------------------------------  def update    last_real_x = @real_x - @upx    last_real_y = @real_y - @upy    last_moving = moving?    move_by_input    super    update_scroll(last_real_x, last_real_y)    if @upy != 0      @y = $game_map.round_y( @y + @upy)      @real_y = @y    end    if @upx != 0        # 这是X轴强制移动的部分,单独和x有关的,基本都是      @x = $game_map.round_x( @x + @upx)      @real_x = @x    end    if @upover == true      @x = @x.to_i  # to_i改成整数,否则将会因为小数而无法触发事件      @y = @y.to_i      @upover = false    end    update_vehicle    update_nonmoving(last_moving) unless moving?    @followers.update  endend
#============================================================================== 
# ■ Game_CharacterBase 
#------------------------------------------------------------------------------ 
#  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。 
#============================================================================== 
  
class Game_Player < Game_Character 
  #-------------------------------------------------------------------------- 
  # ● 定义实例变量 
  #-------------------------------------------------------------------------- 
  attr_accessor   :upy                        # y 每帧增长的y 
  attr_accessor   :upx                        # x 每帧增长的y 
  attr_accessor   :upover                     # 强制位移终止 
  #-------------------------------------------------------------------------- 
  # ● 初始化对象 
  #-------------------------------------------------------------------------- 
  alias init initialize 
  def initialize 
    init 
    @upx = 0 
    @upy = 0  
    @upover = false 
  end 
  #-------------------------------------------------------------------------- 
  # ● 由方向键移动 
  #-------------------------------------------------------------------------- 
  def move_by_input 
    return if !movable? || ($game_map.interpreter.running? and (@upy == 0 and @upx == 0) ) #多加了一个条件 
   #若觉得条件太长,改成@uping的true/false变量,一旦使用强制移动就打开,不使用就false 
    move_straight(Input.dir4) if Input.dir4 > 0 
  end 
  #-------------------------------------------------------------------------- 
  # ● 更新画面  
 #  没有使用alias,请注意插入的位置 
 #-------------------------------------------------------------------------- 
  def update 
    last_real_x = @real_x - @upx 
    last_real_y = @real_y - @upy 
    last_moving = moving? 
    move_by_input 
    super 
    update_scroll(last_real_x, last_real_y) 
    if @upy != 0 
      @y = $game_map.round_y( @y + @upy) 
      @real_y = @y 
    end 
    if @upx != 0        # 这是X轴强制移动的部分,单独和x有关的,基本都是 
      @x = $game_map.round_x( @x + @upx) 
      @real_x = @x 
    end 
    if @upover == true 
      @x = @x.to_i  # to_i改成整数,否则将会因为小数而无法触发事件 
      @y = @y.to_i 
      @upover = false 
    end 
    update_vehicle 
    update_nonmoving(last_moving) unless moving? 
    @followers.update 
  end 
end 
 
 |