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

Project1

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

[已经解决] 请问如何设定 鼠标在区域里触发事件跟随或远离? 1vip

[复制链接]

Lv1.梦旅人

梦石
0
星屑
120
在线时间
72 小时
注册时间
2013-10-6
帖子
50
跳转到指定楼层
1
发表于 2015-8-12 15:42:09 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
3星屑
本帖最后由 doubyen 于 2015-8-15 18:55 编辑

上次高手帮改过一个“鼠标接触图片自动触发事件”的脚本;
现在我有新的悬赏!!
我想在这个脚本的基础上设定鼠标在一个区域里触发事件的自动跟随或自动远离?!
我研究了半天无果……
附图:


请问该怎么改??还是要改动脚本??

改好满意会附上悬赏呵

下面这个是“鼠标接触图片自动触发事件”的脚本
##################################################################################################################
#===========================================================
#===================
# 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
# 非原装鼠标脚本
#==============================================================================

#=================以下两个用来调整战斗时的手感问题,可以自己试试。
$敌人选框扩大 = 20
$角色选框扩大 = 30


#==============================================================================
# API调用
#==============================================================================
$ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
$GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
$ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
$GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
$Window_HWND = $GetActiveWindow.call
$GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
#$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')#
#$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)#
#$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)#
#$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')#
#$Window_HWND = $FindWindow.call(nil, 'mousetry')#

module Mouse  
  LEFT = 0x01
  RIGHT = 0x02

  def self.init(sprite = nil)
   #$HookStart.call($Window_HWND)#
    $ShowCursor.call(0)
   
    @show_cursor = false
   
    @mouse_sprite = Sprite.new
    @mouse_sprite.z = 99999
    @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/002-Weapon02")
    @mouse_sprite2 = Sprite.new
    @mouse_sprite2.z = @mouse_sprite.z - 1
    #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
    @left_press = false
    @right_press = false
    @left_trigger = false
    @right_trigger = false
    @left_repeat = false
    @right_repeat = false
    @click_lock = false
   
    update
  end
#-----------------------------------------------#----------------------------------------
  def self.exit
    @mouse_sprite.bitmap.dispose
    @mouse_sprite.dispose
    @show_cursor = true
   # $HookEnd.call#
    $ShowCursor.call(1)
  end
  def self.mouse_debug
    return @mouse_debug.bitmap
  end
  def self.update
    left_down = $GetKeyState.call(0x01)
    right_down = $GetKeyState.call(0x02)
    if $build == true
      $cursor_pic = Bitmap.new("Graphics/Icons/002-Weapon01")
      @mouse_sprite2.bitmap=Bitmap.new("Graphics/Icons/002-Weapon01")
      @mouse_sprite2.ox=$cursor_pic.width-32
      @mouse_sprite2.oy=$cursor_pic.height-32
    else
      @mouse_sprite2.bitmap=Bitmap.new(32,32)
    end
    @click_lock = false
    mouse_x, mouse_y = self.get_mouse_pos
    @mouse_sprite.x = mouse_x
    @mouse_sprite.y = mouse_y
    @mouse_sprite2.x = (mouse_x/32)*32
    @mouse_sprite2.y = (mouse_y/32)*32
    if $build  == false
    @mouse_sprite2.opacity=255
    else
    @mouse_sprite2.opacity=160
    end
    if left_down[7] == 1
      @left_repeat = (not @left_repeat)
      @left_trigger = (not @left_press)
      @left_press = true
    else
      @left_press = false
      @left_trigger = false
      @left_repeat = false
    end
    if right_down[7] == 1
      @right_repeat = (not @right_repeat)
      @right_trigger = (not @right_press)
      @right_press = true
    else
      @right_press = false
      @right_trigger = false
      @right_repeat = false
    end
  end
  def self.get_mouse_pos
    point_var = [0, 0].pack('ll')
    if $GetCursorPos.call(point_var) != 0
      if $ScreenToClient.call($Window_HWND, point_var) != 0
        x, y = point_var.unpack('ll')
        if (x < 0) or (x > 10000) then x = 0 end
        if (y < 0) or (y > 10000) then y = 0 end
        if x > 1275 then x = 1275 end
        if y > 795 then y = 795 end
        return x, y
      else
        return 0, 0
      end
    else
      return 0, 0
    end
  end
  def self.press?(mouse_code)
    if mouse_code == LEFT
      if @click_lock
        return false
      else
        return @left_press
      end
    elsif mouse_code == RIGHT
      return @right_press
    else
      return false
    end
  end
  def self.trigger?(mouse_code)
    if mouse_code == LEFT
      if @click_lock
        return false
      else
        return @left_trigger
      end
    elsif mouse_code == RIGHT
      return @right_trigger
    else
      return false
    end
  end
  def self.repeat?(mouse_code)
    if mouse_code == LEFT
      if @click_lock
        return false
      else
        return @left_repeat
      end
    elsif mouse_code == RIGHT
      return @right_repeat
    else
      return false
    end
  end
  def self.click_lock?
    return @click_lock
  end
  def self.click_lock
    @click_lock = true
  end
  def self.click_unlock
    @click_lock = false
  end
end
module Input
  if @self_update == nil
    @self_update = method('update')
    @self_press = method('press?')
    @self_trigger = method('trigger?')
    @self_repeat = method('repeat?')
        
  end
  def self.update
    @self_update.call
    Mouse.update
  end
  def self.press?(key_code)
    if @self_press.call(key_code)
      return true
    end
    if key_code == C
      return Mouse.press?(Mouse::LEFT)
    elsif key_code == B
      return Mouse.press?(Mouse::RIGHT)
    else
      return @self_press.call(key_code)
    end
  end
  def self.trigger?(key_code)
    if @self_trigger.call(key_code)
      return true
    end
    if key_code == C
      return Mouse.trigger?(Mouse::LEFT)
    elsif key_code == B
      return Mouse.trigger?(Mouse::RIGHT)
    else
      return @self_trigger.call(key_code)
    end
  end
  def self.repeat?(key_code)
    if @self_repeat.call(key_code)
      return true
    end
    if key_code == C
      return Mouse.repeat?(Mouse::LEFT)
    elsif key_code == B
      return Mouse.repeat?(Mouse::RIGHT)
    else
      return @self_repeat.call(key_code)
    end
  end
end

class Window_Selectable
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    #self.cursor_rect.empty
    self_update
    if self.active and @item_max > 0
      index_var = @index
      tp_index = @index
      mouse_x, mouse_y = Mouse.get_mouse_pos
      mouse_not_in_rect = true
      for i in 0...@item_max
        @index = i
        update_cursor_rect
        top_x = self.cursor_rect.x + self.x + 16
        top_y = self.cursor_rect.y + self.y + 16
        bottom_x = top_x + self.cursor_rect.width
        bottom_y = top_y + self.cursor_rect.height
        if (mouse_x > top_x) and (mouse_y > top_y) and
           (mouse_x < bottom_x) and (mouse_y < bottom_y)
          mouse_not_in_rect = false
          if tp_index != @index
            tp_index = @index
            $game_system.se_play($data_system.cursor_se)
          end
          break
        end
      end
      if mouse_not_in_rect
        @index = index_var
        update_cursor_rect
        Mouse.click_lock
      else
        Mouse.click_unlock               
      end
    end
  end
end
class Window_NameInput
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    #self.cursor_rect.empty
    self_update
    if self.active
      index_var = @index
      mouse_x, mouse_y = Mouse.get_mouse_pos
      mouse_not_in_rect = true
      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
        @index = i
        update_cursor_rect
        top_x = self.cursor_rect.x + self.x + 16
        top_y = self.cursor_rect.y + self.y + 16
        bottom_x = top_x + self.cursor_rect.width
        bottom_y = top_y + self.cursor_rect.height
        #
        if (mouse_x > top_x) and (mouse_y > top_y) and
           (mouse_x < bottom_x) and (mouse_y < bottom_y)
          mouse_not_in_rect = false
          break
        end
      end
      if mouse_not_in_rect
        @index = index_var
        update_cursor_rect
        Mouse.click_lock
      else
        Mouse.click_unlock
      end
    end
  end
end
class Window_InputNumber
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    #self.cursor_rect.empty
    self_update
    mouse_x, mouse_y = Mouse.get_mouse_pos
    if self.active and @digits_max > 0
      index_var = @index
      mouse_not_in_rect = true
      for i in 0...@digits_max
        @index = i
        update_cursor_rect
        top_x = self.cursor_rect.x + self.x + 16
        bottom_x = top_x + self.cursor_rect.width
        #
        if (mouse_x > top_x) and (mouse_x < bottom_x)
          mouse_not_in_rect = false
          break
        end
      end
      if mouse_not_in_rect
        @index = index_var
        update_cursor_rect
        Mouse.click_lock
      else
        Mouse.click_unlock
      end
    end
    if @last_mouse_y == nil
      @last_mouse_y = mouse_y
    end
    check_pos = (@last_mouse_y - mouse_y).abs
    if check_pos > 10
      $game_system.se_play($data_system.cursor_se)
      place = 10 ** (@digits_max - 1 - @index)
      n = @number / place % 10
      @number -= n * place
      n = (n + 1) % 10 if mouse_y < @last_mouse_y
      n = (n + 9) % 10 if mouse_y > @last_mouse_y
      @number += n * place
      refresh
      @last_mouse_y = mouse_y
    end
  end
end
class Scene_File
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    mouse_x, mouse_y = Mouse.get_mouse_pos
    Mouse.click_lock
    idx = 0
    for i in @savefile_windows
      top_x = i.x + 16
      top_y = i.y + 16
      bottom_x = top_x + i.width
      bottom_y = top_y + i.height
      if (mouse_x > top_x) and (mouse_y > top_y) and
         (mouse_x < bottom_x) and (mouse_y < bottom_y)
        i.selected = true
        if @file_index != idx
          @file_index = idx
          $game_system.se_play($data_system.cursor_se)
        end            
        Mouse.click_unlock
      else
        i.selected = false
      end
      idx += 1
    end
    self_update
  end
end
class Arrow_Enemy
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    mouse_x, mouse_y = Mouse.get_mouse_pos
    idx = 0
    for i in $game_troop.enemies do
      if i.exist?
        top_x = i.screen_x - self.ox
        top_y = i.screen_y - self.oy
        bottom_x = top_x + self.src_rect.width
        bottom_y = top_y + self.src_rect.height
        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
          if @index != idx
            $game_system.se_play($data_system.cursor_se)
            @index = idx
          end
        end
      end
      idx += 1
    end
    self_update
  end
end
class Arrow_Actor
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    mouse_x, mouse_y = Mouse.get_mouse_pos
    idx = 0
    for i in $game_party.actors do
      if i.exist?
        top_x = i.screen_x - self.ox
        top_y = i.screen_y - self.oy
        bottom_x = top_x + self.src_rect.width
        bottom_y = top_y + self.src_rect.height
        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
          if @index != idx
            $game_system.se_play($data_system.cursor_se)
            @index = idx
          end
        end
      end
      idx += 1
    end
    self_update
  end
end
class Game_Player
  if @self_alias == nil
    alias self_update update
    @self_alias = true
  end
  def update
    mouse_x, mouse_y = Mouse.get_mouse_pos

    if @last_move_x == nil
      @last_move_x = false
    end
   
     
     #if Mouse.trigger?(Mouse::RIGHT)
      
     self_update


    if Mouse.press?(Mouse::LEFT) or  $game_switches[4] == true
     last_moving = moving?
      last_direction = @direction
     unless moving? or $game_system.map_interpreter.running? or
             @move_route_forcing or $game_temp.message_window_showing
        last_x = @x
        if @last_move_x
          @last_move_x = false
       elsif mouse_x > screen_x + 16
          move_right
          @wait_count = 10
        elsif mouse_x < screen_x - 16
          move_left
          @wait_count = 10
        end
        last_y = @y
      if last_x != @x
          @last_move_x = true
       elsif mouse_y > screen_y
   move_down
   @wait_count = 10
        elsif mouse_y < screen_y - 32
          move_up
          @wait_count = 10
        end
        if last_y != @y
          @last_move_x = false
        elsif not @last_move_x
          case last_direction
          when 2
            turn_down
          when 4
            turn_left
          when 6
            turn_right
          when 8
            turn_up
          end
        end
      end
    end
    self_update
  end
end

Mouse.init
END { Mouse.exit }




#==============================================================================
# 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
#==============================================================================
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#格式:显示的cmd图片的命名格式为:
#    cmd调用公共事件编号_名字
#    cmd调用公共事件编号_名字_2 # 此为鼠标经过的图片
#
#即,带有cmd的为可以点击的图片,点击后执行相应的公共事件.....
#不带cmd的图片没任何影响。。。
#==============================================================================
class Game_Picture

def name=(str)
   @name = str
end

end

class Sprite_Picture

alias update_old update
def update
   update_old
   return if @picture_name == "" or @picture_name[/cmd/].nil?
   mx,my = Mouse.get_mouse_pos
   lx = self.x - self.ox
   rx = lx + self.bitmap.width
   ty = self.y - self.oy
   by = ty + self.bitmap.height
   if mx < lx or mx > rx or my < ty or my > by or
     self.bitmap.get_pixel(mx-lx,my-ty).alpha == 0
     @picture.name = @picture.name.split(/_/)[0]+"_"[email protected](/_/)[1]
     return
   end
   if @picture.name.split(/_/)[2].nil?
#    Audio.se_play("Audio/SE/sound00.wav")
     @picture.name = @picture.name + "_2"
          @picture.name.split(/_/)[0].sub(/cmd([0-9]+)/,"")
     $game_temp.common_event_id = $1.to_i
   end
end

end


##################################################################################################################

最佳答案

查看完整内容

嗯...不改变原有的鼠标脚本是可以的, 不过我还是另外添加了一小段新脚本来帮助事件更顺畅的行走。 (不用修改原来的鼠标脚本,把新添的脚本加入即可) 不知道这次有没有正确理解 doubyen 君的意思, 只是把上一个范例简单修改(套路一样,对象不同),具体新范例都有注释。 还有,需要把事件搬回你原来的工程里,才能测试效果, 因为“move_toward_event(x)”是您原来工程的脚本内容哦。 ...

Lv1.梦旅人

梦石
0
星屑
50
在线时间
126 小时
注册时间
2015-2-4
帖子
17
2
发表于 2015-8-12 15:42:10 | 只看该作者
doubyen 发表于 2015-8-15 06:51
感谢luoxduo的耐心回复,看来我们理解的不一样…… 我也做了范例,呈上

之前luoxduo提到过在不 ...

嗯...不改变原有的鼠标脚本是可以的,
不过我还是另外添加了一小段新脚本来帮助事件更顺畅的行走。
(不用修改原来的鼠标脚本,把新添的脚本加入即可)

不知道这次有没有正确理解 doubyen 君的意思,
只是把上一个范例简单修改(套路一样,对象不同),具体新范例都有注释。

还有,需要把事件搬回你原来的工程里,才能测试效果,
因为“move_toward_event(x)”是您原来工程的脚本内容哦。

蝴蝶事件.7z

202.26 KB, 下载次数: 81

回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
126 小时
注册时间
2015-2-4
帖子
17
3
发表于 2015-8-13 14:59:16 | 只看该作者
本帖最后由 luoxduo 于 2015-8-13 15:01 编辑

首先,根据lz的思路,要先获取鼠标的坐标,需要小小修改下脚本
  1. ##################################################################################################################
  2. #===========================================================
  3. #===================
  4. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  5. # 非原装鼠标脚本
  6. #==============================================================================

  7. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  8. $敌人选框扩大 = 20
  9. $角色选框扩大 = 30


  10. #==============================================================================
  11. # API调用
  12. #==============================================================================
  13. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  14. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  15. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  16. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  17. $Window_HWND = $GetActiveWindow.call
  18. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  19. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')#
  20. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)#
  21. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)#
  22. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')#
  23. #$Window_HWND = $FindWindow.call(nil, 'mousetry')#

  24. module Mouse  
  25.   LEFT = 0x01
  26.   RIGHT = 0x02

  27.   def self.init(sprite = nil)
  28.    #$HookStart.call($Window_HWND)#
  29.     $ShowCursor.call(0)
  30.    
  31.     @show_cursor = false
  32.    
  33.     @mouse_sprite = Sprite.new
  34.     @mouse_sprite.z = 99999
  35.     @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/002-Weapon02")
  36.     @mouse_sprite2 = Sprite.new
  37.     @mouse_sprite2.z = @mouse_sprite.z - 1
  38.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  39.     @left_press = false
  40.     @right_press = false
  41.     @left_trigger = false
  42.     @right_trigger = false
  43.     @left_repeat = false
  44.     @right_repeat = false
  45.     @click_lock = false
  46.    
  47.     update
  48.   end
  49. #-----------------------------------------------#----------------------------------------
  50.   def self.exit
  51.     @mouse_sprite.bitmap.dispose
  52.     @mouse_sprite.dispose
  53.     @show_cursor = true
  54.    # $HookEnd.call#
  55.     $ShowCursor.call(1)
  56.   end
  57.   def self.mouse_debug
  58.     return @mouse_debug.bitmap
  59.   end
  60.   def self.update
  61.     left_down = $GetKeyState.call(0x01)
  62.     right_down = $GetKeyState.call(0x02)
  63.     if $build == true
  64.       $cursor_pic = Bitmap.new("Graphics/Icons/002-Weapon01")
  65.       @mouse_sprite2.bitmap=Bitmap.new("Graphics/Icons/002-Weapon01")
  66.       @mouse_sprite2.ox=$cursor_pic.width-32
  67.       @mouse_sprite2.oy=$cursor_pic.height-32
  68.     else
  69.       @mouse_sprite2.bitmap=Bitmap.new(32,32)
  70.     end
  71.     @click_lock = false
  72.     mouse_x, mouse_y = self.get_mouse_pos
  73.     @mouse_sprite.x = mouse_x
  74.     @mouse_sprite.y = mouse_y
  75.     @mouse_sprite2.x = (mouse_x/32)*32
  76.     @mouse_sprite2.y = (mouse_y/32)*32
  77.     if $build  == false
  78.     @mouse_sprite2.opacity=255
  79.     else
  80.     @mouse_sprite2.opacity=160
  81.     end
  82.     if left_down[7] == 1
  83.       @left_repeat = (not @left_repeat)
  84.       @left_trigger = (not @left_press)
  85.       @left_press = true
  86.     else
  87.       @left_press = false
  88.       @left_trigger = false
  89.       @left_repeat = false
  90.     end
  91.     if right_down[7] == 1
  92.       @right_repeat = (not @right_repeat)
  93.       @right_trigger = (not @right_press)
  94.       @right_press = true
  95.     else
  96.       @right_press = false
  97.       @right_trigger = false
  98.       @right_repeat = false
  99.     end
  100.   end
  101.   def self.get_mouse_pos
  102.     point_var = [0, 0].pack('ll')
  103.     if $GetCursorPos.call(point_var) != 0
  104.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  105.         x, y = point_var.unpack('ll')
  106.         if (x < 0) or (x > 10000) then x = 0 end
  107.         if (y < 0) or (y > 10000) then y = 0 end
  108.         if x > 1275 then x = 1275 end
  109.         if y > 795 then y = 795 end
  110.         return x, y
  111.       else
  112.         return 0, 0
  113.       end
  114.     else
  115.       return 0, 0
  116.     end
  117.   end
  118.   def self.press?(mouse_code)
  119.     if mouse_code == LEFT
  120.       if @click_lock
  121.         return false
  122.       else
  123.         return @left_press
  124.       end
  125.     elsif mouse_code == RIGHT
  126.       return @right_press
  127.     else
  128.       return false
  129.     end
  130.   end
  131.   def self.trigger?(mouse_code)
  132.     if mouse_code == LEFT
  133.       if @click_lock
  134.         return false
  135.       else
  136.         return @left_trigger
  137.       end
  138.     elsif mouse_code == RIGHT
  139.       return @right_trigger
  140.     else
  141.       return false
  142.     end
  143.   end
  144.   def self.repeat?(mouse_code)
  145.     if mouse_code == LEFT
  146.       if @click_lock
  147.         return false
  148.       else
  149.         return @left_repeat
  150.       end
  151.     elsif mouse_code == RIGHT
  152.       return @right_repeat
  153.     else
  154.       return false
  155.     end
  156.   end
  157.   def self.click_lock?
  158.     return @click_lock
  159.   end
  160.   def self.click_lock
  161.     @click_lock = true
  162.   end
  163.   def self.click_unlock
  164.     @click_lock = false
  165.   end
  166. end
  167. module Input
  168.   if @self_update == nil
  169.     @self_update = method('update')
  170.     @self_press = method('press?')
  171.     @self_trigger = method('trigger?')
  172.     @self_repeat = method('repeat?')
  173.         
  174.   end
  175.   def self.update
  176.     @self_update.call
  177.     Mouse.update
  178.   end
  179.   def self.press?(key_code)
  180.     if @self_press.call(key_code)
  181.       return true
  182.     end
  183.     if key_code == C
  184.       return Mouse.press?(Mouse::LEFT)
  185.     elsif key_code == B
  186.       return Mouse.press?(Mouse::RIGHT)
  187.     else
  188.       return @self_press.call(key_code)
  189.     end
  190.   end
  191.   def self.trigger?(key_code)
  192.     if @self_trigger.call(key_code)
  193.       return true
  194.     end
  195.     if key_code == C
  196.       return Mouse.trigger?(Mouse::LEFT)
  197.     elsif key_code == B
  198.       return Mouse.trigger?(Mouse::RIGHT)
  199.     else
  200.       return @self_trigger.call(key_code)
  201.     end
  202.   end
  203.   def self.repeat?(key_code)
  204.     if @self_repeat.call(key_code)
  205.       return true
  206.     end
  207.     if key_code == C
  208.       return Mouse.repeat?(Mouse::LEFT)
  209.     elsif key_code == B
  210.       return Mouse.repeat?(Mouse::RIGHT)
  211.     else
  212.       return @self_repeat.call(key_code)
  213.     end
  214.   end
  215. end

  216. class Window_Selectable
  217.   if @self_alias == nil
  218.     alias self_update update
  219.     @self_alias = true
  220.   end
  221.   def update
  222.     #self.cursor_rect.empty
  223.     self_update
  224.     if self.active and @item_max > 0
  225.       index_var = @index
  226.       tp_index = @index
  227.       mouse_x, mouse_y = Mouse.get_mouse_pos
  228.       #
  229.       $mouse_x = mouse_x
  230.       $mouse_y = mouse_y
  231.       #
  232.       mouse_not_in_rect = true
  233.       for i in 0...@item_max
  234.         @index = i
  235.         update_cursor_rect
  236.         top_x = self.cursor_rect.x + self.x + 16
  237.         top_y = self.cursor_rect.y + self.y + 16
  238.         bottom_x = top_x + self.cursor_rect.width
  239.         bottom_y = top_y + self.cursor_rect.height
  240.         if (mouse_x > top_x) and (mouse_y > top_y) and
  241.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  242.           mouse_not_in_rect = false
  243.           if tp_index != @index
  244.             tp_index = @index
  245.             $game_system.se_play($data_system.cursor_se)
  246.           end
  247.           break
  248.         end
  249.       end
  250.       if mouse_not_in_rect
  251.         @index = index_var
  252.         update_cursor_rect
  253.         Mouse.click_lock
  254.       else
  255.         Mouse.click_unlock               
  256.       end
  257.     end
  258.   end
  259. end
  260. class Window_NameInput
  261.   if @self_alias == nil
  262.     alias self_update update
  263.     @self_alias = true
  264.   end
  265.   def update
  266.     #self.cursor_rect.empty
  267.     self_update
  268.     if self.active
  269.       index_var = @index
  270.       mouse_x, mouse_y = Mouse.get_mouse_pos
  271.       #
  272.       $mouse_x = mouse_x
  273.       $mouse_y = mouse_y
  274.       #
  275.       mouse_not_in_rect = true
  276.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  277.         @index = i
  278.         update_cursor_rect
  279.         top_x = self.cursor_rect.x + self.x + 16
  280.         top_y = self.cursor_rect.y + self.y + 16
  281.         bottom_x = top_x + self.cursor_rect.width
  282.         bottom_y = top_y + self.cursor_rect.height
  283.         #
  284.         if (mouse_x > top_x) and (mouse_y > top_y) and
  285.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  286.           mouse_not_in_rect = false
  287.           break
  288.         end
  289.       end
  290.       if mouse_not_in_rect
  291.         @index = index_var
  292.         update_cursor_rect
  293.         Mouse.click_lock
  294.       else
  295.         Mouse.click_unlock
  296.       end
  297.     end
  298.   end
  299. end
  300. class Window_InputNumber
  301.   if @self_alias == nil
  302.     alias self_update update
  303.     @self_alias = true
  304.   end
  305.   def update
  306.     #self.cursor_rect.empty
  307.     self_update
  308.     mouse_x, mouse_y = Mouse.get_mouse_pos
  309.     #
  310.       $mouse_x = mouse_x
  311.       $mouse_y = mouse_y
  312.     #
  313.     if self.active and @digits_max > 0
  314.       index_var = @index
  315.       mouse_not_in_rect = true
  316.       for i in 0...@digits_max
  317.         @index = i
  318.         update_cursor_rect
  319.         top_x = self.cursor_rect.x + self.x + 16
  320.         bottom_x = top_x + self.cursor_rect.width
  321.         #
  322.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  323.           mouse_not_in_rect = false
  324.           break
  325.         end
  326.       end
  327.       if mouse_not_in_rect
  328.         @index = index_var
  329.         update_cursor_rect
  330.         Mouse.click_lock
  331.       else
  332.         Mouse.click_unlock
  333.       end
  334.     end
  335.     if @last_mouse_y == nil
  336.       @last_mouse_y = mouse_y
  337.     end
  338.     check_pos = (@last_mouse_y - mouse_y).abs
  339.     if check_pos > 10
  340.       $game_system.se_play($data_system.cursor_se)
  341.       place = 10 ** (@digits_max - 1 - @index)
  342.       n = @number / place % 10
  343.       @number -= n * place
  344.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  345.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  346.       @number += n * place
  347.       refresh
  348.       @last_mouse_y = mouse_y
  349.     end
  350.   end
  351. end
  352. class Scene_File
  353.   if @self_alias == nil
  354.     alias self_update update
  355.     @self_alias = true
  356.   end
  357.   def update
  358.     mouse_x, mouse_y = Mouse.get_mouse_pos
  359.     #
  360.       $mouse_x = mouse_x
  361.       $mouse_y = mouse_y
  362.     #
  363.     Mouse.click_lock
  364.     idx = 0
  365.     for i in @savefile_windows
  366.       top_x = i.x + 16
  367.       top_y = i.y + 16
  368.       bottom_x = top_x + i.width
  369.       bottom_y = top_y + i.height
  370.       if (mouse_x > top_x) and (mouse_y > top_y) and
  371.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  372.         i.selected = true
  373.         if @file_index != idx
  374.           @file_index = idx
  375.           $game_system.se_play($data_system.cursor_se)
  376.         end            
  377.         Mouse.click_unlock
  378.       else
  379.         i.selected = false
  380.       end
  381.       idx += 1
  382.     end
  383.     self_update
  384.   end
  385. end
  386. class Arrow_Enemy
  387.   if @self_alias == nil
  388.     alias self_update update
  389.     @self_alias = true
  390.   end
  391.   def update
  392.     mouse_x, mouse_y = Mouse.get_mouse_pos
  393.     #
  394.       $mouse_x = mouse_x
  395.       $mouse_y = mouse_y
  396.     #
  397.     idx = 0
  398.     for i in $game_troop.enemies do
  399.       if i.exist?
  400.         top_x = i.screen_x - self.ox
  401.         top_y = i.screen_y - self.oy
  402.         bottom_x = top_x + self.src_rect.width
  403.         bottom_y = top_y + self.src_rect.height
  404.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  405.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  406.           if @index != idx
  407.             $game_system.se_play($data_system.cursor_se)
  408.             @index = idx
  409.           end
  410.         end
  411.       end
  412.       idx += 1
  413.     end
  414.     self_update
  415.   end
  416. end
  417. class Arrow_Actor
  418.   if @self_alias == nil
  419.     alias self_update update
  420.     @self_alias = true
  421.   end
  422.   def update
  423.     mouse_x, mouse_y = Mouse.get_mouse_pos
  424.     #
  425.       $mouse_x = mouse_x
  426.       $mouse_y = mouse_y
  427.     #
  428.     idx = 0
  429.     for i in $game_party.actors do
  430.       if i.exist?
  431.         top_x = i.screen_x - self.ox
  432.         top_y = i.screen_y - self.oy
  433.         bottom_x = top_x + self.src_rect.width
  434.         bottom_y = top_y + self.src_rect.height
  435.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  436.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  437.           if @index != idx
  438.             $game_system.se_play($data_system.cursor_se)
  439.             @index = idx
  440.           end
  441.         end
  442.       end
  443.       idx += 1
  444.     end
  445.     self_update
  446.   end
  447. end
  448. class Game_Player
  449.   if @self_alias == nil
  450.     alias self_update update
  451.     @self_alias = true
  452.   end
  453.   def update
  454.     mouse_x, mouse_y = Mouse.get_mouse_pos
  455.     #
  456.       $mouse_x = mouse_x
  457.       $mouse_y = mouse_y
  458.     #
  459.     if @last_move_x == nil
  460.       @last_move_x = false
  461.     end
  462.    
  463.      
  464.      #if Mouse.trigger?(Mouse::RIGHT)
  465.       
  466.      self_update


  467.     if Mouse.press?(Mouse::LEFT) or  $game_switches[4] == true
  468.      last_moving = moving?
  469.       last_direction = @direction
  470.      unless moving? or $game_system.map_interpreter.running? or
  471.              @move_route_forcing or $game_temp.message_window_showing
  472.         last_x = @x
  473.         if @last_move_x
  474.           @last_move_x = false
  475.        elsif mouse_x > screen_x + 16
  476.           move_right
  477.           @wait_count = 10
  478.         elsif mouse_x < screen_x - 16
  479.           move_left
  480.           @wait_count = 10
  481.         end
  482.         last_y = @y
  483.       if last_x != @x
  484.           @last_move_x = true
  485.        elsif mouse_y > screen_y
  486.    move_down
  487.    @wait_count = 10
  488.         elsif mouse_y < screen_y - 32
  489.           move_up
  490.           @wait_count = 10
  491.         end
  492.         if last_y != @y
  493.           @last_move_x = false
  494.         elsif not @last_move_x
  495.           case last_direction
  496.           when 2
  497.             turn_down
  498.           when 4
  499.             turn_left
  500.           when 6
  501.             turn_right
  502.           when 8
  503.             turn_up
  504.           end
  505.         end
  506.       end
  507.     end
  508.     self_update
  509.   end
  510. end

  511. Mouse.init
  512. END { Mouse.exit }
复制代码
这样子,$mouse_x和$mouse_y就分别代表鼠标在画面的x,y坐标了。

然后,lz图示的效果有错误。。条件
“x<6,x>8”“y<13,y>15”
结果x,y两个数都不存在。
应该是:
“x>6,x<8”“y>13,y<15”


最后,要达到“区域里触发事件的自动跟随或自动远离”的效果,有个简单的方法:
在需要效果的事件里,移动规则→类型→自定义→移动路线→脚本
插入两次脚本
  1. move_toward_player  if  $mouse_x > 6 and $mouse_x < 8 and $mouse_y > 13 and $mouse_y < 15 #接近
复制代码
  1. move_away_from_player  if  $mouse_x < 6 or $mouse_x > 8 or $mouse_y < 13 or $mouse_y > 15 #远离
复制代码
if "后面的内容"是开启if"前面的内容“的条件,move_toward_player是接近,move_away_from_player 是远离,and是和,or是或。
嗯...lz图示的条件范围太窄啦,不好测试效果,把它改成
  1. move_toward_player  if  $mouse_x > 600 and $mouse_x < 640 and $mouse_y > 400 and $mouse_y < 480 #接近
复制代码
  1. move_away_from_player  if  $mouse_x < 600 or $mouse_x > 640 or $mouse_y < 400 or $mouse_y > 480 #远离
复制代码
lz试试把鼠标放到窗口画面右下角,是不是有效果啦。。
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1034
在线时间
749 小时
注册时间
2013-2-15
帖子
116

开拓者

4
发表于 2015-8-13 15:56:55 | 只看该作者
本帖最后由 九幽鬼少 于 2015-8-13 16:06 编辑

其实一个傻方法 在地图上设置一个事件  并行处理
事件内容 一个脚本
  1. xxx,yyy = Mouse.get_mouse_pos
  2. if xxx > 0 and yyy > 0 and xxx < 50 and yyy < 50
  3.   p 1 #要执行的内容
  4. end
复制代码
第一个0代表 范围的x
第二个0代表 范围的x
第一个50代表 范围的宽度
第二个50代表 范围的高度

也可以这样子
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
72 小时
注册时间
2013-10-6
帖子
50
5
 楼主| 发表于 2015-8-14 10:04:49 | 只看该作者
九幽鬼少 发表于 2015-8-13 15:56
其实一个傻方法 在地图上设置一个事件  并行处理
事件内容 一个脚本第一个0代表 范围的x
第二个0代表 范围 ...

可能我的图有误导性,设置移动路线上并不是要角色也就是事件靠近主角,而是要靠近或远离鼠标位置,这个程序我不知道怎么实现??
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1034
在线时间
749 小时
注册时间
2013-2-15
帖子
116

开拓者

6
发表于 2015-8-14 10:15:31 | 只看该作者
doubyen 发表于 2015-8-14 10:04
可能我的图有误导性,设置移动路线上并不是要角色也就是事件靠近主角,而是要靠近或远离鼠标位置,这个程 ...

鼠标在指定范围内让事件远离鼠标位置?
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
72 小时
注册时间
2013-10-6
帖子
50
7
 楼主| 发表于 2015-8-14 12:07:56 | 只看该作者
九幽鬼少 发表于 2015-8-14 10:15
鼠标在指定范围内让事件远离鼠标位置?

接近或是远离,这两种效果我都需要 呵呵^_^
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
126 小时
注册时间
2015-2-4
帖子
17
8
发表于 2015-8-14 15:46:57 | 只看该作者
本帖最后由 luoxduo 于 2015-8-14 15:52 编辑
doubyen 发表于 2015-8-14 12:07
接近或是远离,这两种效果我都需要 呵呵^_^

(;´Д`)居然无视我的答案,好吧

要靠近或远离鼠标位置

我的方法需要修改脚本。(瞎改的,虽然不修改也可以达成...但是每次使用前都要调入太麻烦啊)

脚本太刷屏


方法:需要靠近鼠标的话,在事件移动路线中的脚本 move_kjsb
         需要远离鼠标的话,在事件移动路线中的脚本 move_ylsb

另外,$sb_x和$sb_y分别代表鼠标在地图上的x(横轴)和y(竖轴)坐标
$mouse_x和$mouse_y分别代表鼠标在画面上的x(横轴)和y(竖轴)坐标

最后,想达到 lz 的终极效果,请您参考并灵活应用楼上的所有回答~
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
72 小时
注册时间
2013-10-6
帖子
50
9
 楼主| 发表于 2015-8-14 16:55:54 | 只看该作者
luoxduo 发表于 2015-8-14 15:46
(;´Д`)居然无视我的答案,好吧

刚发现,看一下先~~
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
72 小时
注册时间
2013-10-6
帖子
50
10
 楼主| 发表于 2015-8-14 17:02:14 | 只看该作者
luoxduo 发表于 2015-8-14 15:46
(;´Д`)居然无视我的答案,好吧

刚发现,看一下先~~,如果不修改脚本,是否可以直接调入move_kjsb/move_ylsb ??
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-2 19:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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