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

Project1

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

[已经过期] 怎样让鼠标移动到图片上鼠标变为图片1,点左键变图片2?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
155
在线时间
332 小时
注册时间
2013-7-6
帖子
356
跳转到指定楼层
1
发表于 2014-6-11 12:21:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
怎样让鼠标移动到图片上鼠标变为图片1,点左键变图片2?
这是脚本
鼠标:
RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4.  
  5. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  6. $敌人选框扩大 = 20
  7. $角色选框扩大 = 30
  8.  
  9.  
  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.  
  25. module Mouse  
  26.   LEFT = 0x01
  27.   RIGHT = 0x02
  28.  
  29.   def self.init(sprite = nil)
  30. #   $HookStart.call($Window_HWND)
  31.     $ShowCursor.call(0)
  32.  
  33.     @show_cursor = false
  34.  
  35.     @mouse_sprite = Sprite.new
  36.     @mouse_sprite.z = 99999
  37.    if $a = 1
  38.       @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/光标2.png')
  39.      end
  40.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/光标.png')
  41.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  42.  
  43.     @left_press = false
  44.     @right_press = false
  45.     @left_trigger = false
  46.     @right_trigger = false
  47.     @left_repeat = false
  48.     @right_repeat = false
  49.     @click_lock = false
  50.  
  51.     update
  52.   end
  53.   def self.exit
  54.     @mouse_sprite.bitmap.dispose
  55.     @mouse_sprite.dispose
  56.     @show_cursor = true
  57. #    $HookEnd.call
  58.     $ShowCursor.call(1)
  59.   end
  60.   def self.mouse_debug
  61.     return @mouse_debug.bitmap
  62.   end
  63.   def self.update
  64.     left_down = $GetKeyState.call(0x01)
  65.     right_down = $GetKeyState.call(0x02)
  66.  
  67.     @click_lock = false
  68.     mouse_x, mouse_y = self.get_mouse_pos
  69.     if @mouse_sprite != nil
  70.       @mouse_sprite.x = mouse_x
  71.       @mouse_sprite.y = mouse_y
  72.     end
  73.     if left_down[7] == 1
  74.       @left_repeat = (not @left_repeat)
  75.       @left_trigger = (not @left_press)
  76.       @left_press = true
  77.     else
  78.       @left_press = false
  79.       @left_trigger = false
  80.       @left_repeat = false
  81.     end
  82.     if right_down[7] == 1
  83.       @right_repeat = (not @right_repeat)
  84.       @right_trigger = (not @right_press)
  85.       @right_press = true
  86.     else
  87.       @right_press = false
  88.       @right_trigger = false
  89.       @right_repeat = false
  90.     end
  91.   end
  92.   def self.get_mouse_pos
  93.     point_var = [0, 0].pack('ll')
  94.     if $GetCursorPos.call(point_var) != 0
  95.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  96.         x, y = point_var.unpack('ll')
  97.         if (x < 0) or (x > 10000) then x = 0 end
  98.         if (y < 0) or (y > 10000) then y = 0 end
  99.         if x > 800 then x = 600 end
  100.         if y > 800 then y = 600 end
  101.         return x, y
  102.       else
  103.         return 0, 0
  104.       end
  105.     else
  106.       return 0, 0
  107.     end
  108.   end
  109.   def self.press?(mouse_code)
  110.     if mouse_code == LEFT
  111.       if @click_lock
  112.         return false
  113.       else
  114.         return @left_press
  115.       end
  116.     elsif mouse_code == RIGHT
  117.       return @right_press
  118.     else
  119.       return false
  120.     end
  121.   end
  122.   def self.trigger?(mouse_code)
  123.     if mouse_code == LEFT
  124.       if @click_lock
  125.         return false
  126.       else
  127.         return @left_trigger
  128.       end
  129.     elsif mouse_code == RIGHT
  130.       return @right_trigger
  131.     else
  132.       return false
  133.     end
  134.   end
  135.   def self.repeat?(mouse_code)
  136.     if mouse_code == LEFT
  137.       if @click_lock
  138.         return false
  139.       else
  140.         return @left_repeat
  141.       end
  142.     elsif mouse_code == RIGHT
  143.       return @right_repeat
  144.     else
  145.       return false
  146.     end
  147.   end
  148.   def self.click_lock?
  149.     return @click_lock
  150.   end
  151.   def self.click_lock
  152.     @click_lock = true
  153.   end
  154.   def self.click_unlock
  155.     @click_lock = false
  156.   end
  157. end
  158. module Input
  159.   if @self_update == nil
  160.     @self_update = method('update')
  161.     @self_press = method('press?')
  162.     @self_trigger = method('trigger?')
  163.     @self_repeat = method('repeat?')
  164.   end
  165.   def self.update
  166.     @self_update.call
  167.     Mouse.update
  168.   end
  169.   def self.press?(key_code)
  170.     if @self_press.call(key_code)
  171.       return true
  172.     end
  173.     if key_code == C
  174.       return Mouse.press?(Mouse::LEFT)
  175.     elsif key_code == B
  176.       return Mouse.press?(Mouse::RIGHT)
  177.     else
  178.       return @self_press.call(key_code)
  179.     end
  180.   end
  181.   def self.trigger?(key_code)
  182.     if @self_trigger.call(key_code)
  183.       return true
  184.     end
  185.     if key_code == C
  186.       return Mouse.trigger?(Mouse::LEFT)
  187.     elsif key_code == B
  188.       return Mouse.trigger?(Mouse::RIGHT)
  189.     else
  190.       return @self_trigger.call(key_code)
  191.     end
  192.   end
  193.   def self.repeat?(key_code)
  194.     if @self_repeat.call(key_code)
  195.       return true
  196.     end
  197.     if key_code == C
  198.       return Mouse.repeat?(Mouse::LEFT)
  199.     elsif key_code == B
  200.       return Mouse.repeat?(Mouse::RIGHT)
  201.     else
  202.       return @self_repeat.call(key_code)
  203.     end
  204.   end
  205. end
  206. class Window_Selectable
  207.   if @self_alias == nil
  208.     alias self_update update
  209.     @self_alias = true
  210.   end
  211.   def update
  212.     #self.cursor_rect.empty
  213.     self_update
  214.     if self.active and @item_max > 0
  215.       index_var = @index
  216.       tp_index = @index
  217.       mouse_x, mouse_y = Mouse.get_mouse_pos
  218.       mouse_not_in_rect = true
  219.       for i in 0...@item_max
  220.         @index = i
  221.         update_cursor_rect
  222.         top_x = self.cursor_rect.x + self.x + 16
  223.         top_y = self.cursor_rect.y + self.y + 16
  224.         bottom_x = top_x + self.cursor_rect.width
  225.         bottom_y = top_y + self.cursor_rect.height
  226.         if (mouse_x > top_x) and (mouse_y > top_y) and
  227.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  228.           mouse_not_in_rect = false
  229.           if tp_index != @index
  230.             tp_index = @index
  231.             $game_system.se_play($data_system.cursor_se)
  232.           end
  233.           break
  234.         end
  235.       end
  236.       if mouse_not_in_rect
  237.         @index = index_var
  238.         update_cursor_rect
  239.         Mouse.click_lock
  240.       else
  241.         Mouse.click_unlock               
  242.       end
  243.     end
  244.   end
  245. end
  246. class Window_NameInput
  247.   if @self_alias == nil
  248.     alias self_update update
  249.     @self_alias = true
  250.   end
  251.   def update
  252.     #self.cursor_rect.empty
  253.     self_update
  254.     if self.active
  255.       index_var = @index
  256.       mouse_x, mouse_y = Mouse.get_mouse_pos
  257.       mouse_not_in_rect = true
  258.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  259.         @index = i
  260.         update_cursor_rect
  261.         top_x = self.cursor_rect.x + self.x + 16
  262.         top_y = self.cursor_rect.y + self.y + 16
  263.         bottom_x = top_x + self.cursor_rect.width
  264.         bottom_y = top_y + self.cursor_rect.height
  265.         #
  266.         if (mouse_x > top_x) and (mouse_y > top_y) and
  267.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  268.           mouse_not_in_rect = false
  269.           break
  270.         end
  271.       end
  272.       if mouse_not_in_rect
  273.         @index = index_var
  274.         update_cursor_rect
  275.         Mouse.click_lock
  276.       else
  277.         Mouse.click_unlock
  278.       end
  279.     end
  280.   end
  281. end
  282. class Window_InputNumber
  283.   if @self_alias == nil
  284.     alias self_update update
  285.     @self_alias = true
  286.   end
  287.   def update
  288.     #self.cursor_rect.empty
  289.     self_update
  290.     mouse_x, mouse_y = Mouse.get_mouse_pos
  291.     if self.active and @digits_max > 0
  292.       index_var = @index
  293.       mouse_not_in_rect = true
  294.       for i in 0...@digits_max
  295.         @index = i
  296.         update_cursor_rect
  297.         top_x = self.cursor_rect.x + self.x + 16
  298.         bottom_x = top_x + self.cursor_rect.width
  299.         #
  300.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  301.           mouse_not_in_rect = false
  302.           break
  303.         end
  304.       end
  305.       if mouse_not_in_rect
  306.         @index = index_var
  307.         update_cursor_rect
  308.         Mouse.click_lock
  309.       else
  310.         Mouse.click_unlock
  311.       end
  312.     end
  313.     if @last_mouse_y == nil
  314.       @last_mouse_y = mouse_y
  315.     end
  316.     check_pos = (@last_mouse_y - mouse_y).abs
  317.     if check_pos > 10
  318.       $game_system.se_play($data_system.cursor_se)
  319.       place = 10 ** (@digits_max - 1 - @index)
  320.       n = @number / place % 10
  321.       @number -= n * place
  322.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  323.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  324.       @number += n * place
  325.       refresh
  326.       @last_mouse_y = mouse_y
  327.     end
  328.   end
  329. end
  330. class Scene_File
  331.   if @self_alias == nil
  332.     alias self_update update
  333.     @self_alias = true
  334.   end
  335.   def update
  336.     mouse_x, mouse_y = Mouse.get_mouse_pos
  337.     Mouse.click_lock
  338.     idx = 0
  339.     for i in @savefile_windows
  340.       top_x = i.x + 16
  341.       top_y = i.y + 16
  342.       bottom_x = top_x + i.width
  343.       bottom_y = top_y + i.height
  344.       if (mouse_x > top_x) and (mouse_y > top_y) and
  345.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  346.         i.selected = true
  347.         if @file_index != idx
  348.           @file_index = idx
  349.           $game_system.se_play($data_system.cursor_se)
  350.         end            
  351.         Mouse.click_unlock
  352.       else
  353.         i.selected = false
  354.       end
  355.       idx += 1
  356.     end
  357.     self_update
  358.   end
  359. end
  360. class Arrow_Enemy
  361.   if @self_alias == nil
  362.     alias self_update update
  363.     @self_alias = true
  364.   end
  365.   def update
  366.     mouse_x, mouse_y = Mouse.get_mouse_pos
  367.     idx = 0
  368.     for i in $game_troop.enemies do
  369.       if i.exist?
  370.         top_x = i.screen_x - self.ox
  371.         top_y = i.screen_y - self.oy
  372.         bottom_x = top_x + self.src_rect.width
  373.         bottom_y = top_y + self.src_rect.height
  374.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  375.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  376.           if @index != idx
  377.             $game_system.se_play($data_system.cursor_se)
  378.             @index = idx
  379.           end
  380.         end
  381.       end
  382.       idx += 1
  383.     end
  384.     self_update
  385.   end
  386. end
  387. class Arrow_Actor
  388.   if @self_alias == nil
  389.     alias self_update update
  390.     @self_alias = true
  391.   end
  392.   def update
  393.     mouse_x, mouse_y = Mouse.get_mouse_pos
  394.     idx = 0
  395.     for i in $game_party.actors do
  396.       if i.exist?
  397.         top_x = i.screen_x - self.ox
  398.         top_y = i.screen_y - self.oy
  399.         bottom_x = top_x + self.src_rect.width
  400.         bottom_y = top_y + self.src_rect.height
  401.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  402.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  403.           if @index != idx
  404.             $game_system.se_play($data_system.cursor_se)
  405.             @index = idx
  406.           end
  407.         end
  408.       end
  409.       idx += 1
  410.     end
  411.     self_update
  412.   end
  413. end
  414. class Game_Player
  415.   if @self_alias == nil
  416.     alias self_update update
  417.     @self_alias = true
  418.   end
  419.   def update
  420.     mouse_x, mouse_y = Mouse.get_mouse_pos
  421.  
  422.     if @last_move_x == nil
  423.       @last_move_x = false
  424.     end
  425.   if Mouse.press?(Mouse::RIGHT)
  426.        for event in $game_map.events.values
  427.          if event.screen_x/32 == mouse_x/32 and event.screen_y/32-1 == mouse_y/32
  428.            event.start
  429.          else
  430.            p""
  431.            end
  432.        end
  433.      end
  434.      if Mouse.press?(Mouse::LEFT)
  435.        for event in $game_map.events.values
  436.          if event.screen_x/32 == mouse_x/32 and event.screen_y/32-1 == mouse_y/32
  437.            event.start
  438.            end
  439.        end
  440.      end
  441.      self_update
  442.      return
  443.  
  444.     if Mouse.press?(Mouse::LEFT)
  445.       last_moving = moving?
  446.       last_direction = @direction
  447.       unless moving? or $game_system.map_interpreter.running? or
  448.              @move_route_forcing or $game_temp.message_window_showing
  449.         last_x = @x
  450.         if @last_move_x
  451.           @last_move_x = false
  452.         elsif mouse_x > screen_x + 16
  453.           move_right
  454.         elsif mouse_x < screen_x - 16
  455.           move_left
  456.         end
  457.         last_y = @y
  458.         if last_x != @x
  459.           @last_move_x = true
  460.         elsif mouse_y > screen_y
  461.           move_down
  462.         elsif mouse_y < screen_y - 32
  463.           move_up
  464.         end
  465.         if last_y != @y
  466.           @last_move_x = false
  467.         elsif not @last_move_x
  468.           case last_direction
  469.           when 2
  470.  
  471.           when 4
  472.  
  473.           when 6
  474.  
  475.           when 8
  476.  
  477.           end
  478.         end
  479.       end
  480.     end
  481.     self_update
  482.   end
  483. end
  484. Mouse.init
  485. END { Mouse.exit }
  486.  
  487.  
  488.  
  489.  
  490. #==============================================================================
  491. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  492. #==============================================================================


这是响应图片脚本
RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4. #格式:显示的cmd图片的命名格式为:
  5. #    cmd调用公共事件编号_名字
  6. #    cmd调用公共事件编号_名字_02 # 此为鼠标经过的图片
  7. #
  8. #即,带有cmd的为可以点击的图片,点击后执行相应的公共事件.....
  9. #不带cmd的图片没任何影响。。。
  10. #==============================================================================
  11. class Game_Picture
  12. def name=(str)
  13.    @name = str
  14. end
  15. end
  16.  
  17. class Sprite_Picture
  18. alias update_old update
  19. def update
  20.    update_old
  21.    begin
  22.    return if  @picture_name[/cmd/].nil? or @picture_name == ""
  23. rescue
  24.    return
  25.    end
  26.    mx,my = Mouse.get_mouse_pos
  27.    lx = self.x - self.ox
  28.    rx = lx + self.bitmap.width
  29.    ty = self.y - self.oy
  30.    by = ty + self.bitmap.height
  31.    if mx < lx or mx > rx or my < ty or my > by or
  32.      self.bitmap.get_pixel(mx-lx,my-ty).alpha == 0
  33.  
  34.      @picture.name = @picture.name.split(/_/)[0]+"_"+@picture.name.split(/_/)[1]
  35.      return
  36.    end
  37.    if @picture.name.split(/_/)[2].nil?
  38.      picname = @picture.name + "_02"
  39.      $a = 1
  40.      #第2张图片不存在的时候不显示
  41.      if FileTest.exist?("Graphics/Pictures/#{picname}.png")
  42.        @picture.name = picname
  43.        picname2 = @picture.name.split(/_/)[1] + "map"
  44.        if FileTest.exist?("Graphics/Pictures/#{picname2}.png")
  45.          $mapname = picname2
  46.        end
  47.      end
  48.    end
  49.    #对话框存在的时候不启动事件
  50.      if Mouse.trigger?(Mouse::LEFT) and !$game_system.map_interpreter.running?
  51.        @picture.name.split(/_/)[0].sub(/cmd([0-9]+)/,"")
  52.          $game_temp.common_event_id = $1.to_i
  53.      end
  54. end
  55. end
  56.  
  57. #==============================================================================
  58. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  59. #==============================================================================

求帮忙。。。
偶是熬夜学编程的傻子

Lv3.寻梦者

梦石
0
星屑
2605
在线时间
896 小时
注册时间
2011-4-30
帖子
131

开拓者

2
发表于 2014-6-11 17:52:11 | 只看该作者
$mx,$my = Mouse.get_mouse_pos
条件分歧$mx > 110 and $mx < 290 and $my > 75 and $my < 225
类似的效果。

评分

参与人数 1星屑 +66 收起 理由
天地有正气 + 66 感谢回答

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
155
在线时间
332 小时
注册时间
2013-7-6
帖子
356
3
 楼主| 发表于 2014-6-12 06:41:15 | 只看该作者
只能通过脚本划定区域么。。。
偶是熬夜学编程的傻子
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-30 23:38

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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