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

Project1

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

[已经过期] 鼠标坐标问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
跳转到指定楼层
1
发表于 2012-7-18 18:25:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想问一个关于鼠标的问题,我想设计一个用鼠标打击的游戏,却不知道怎么知道鼠标的坐标,所以想问一下各位
怎么样用变量来知道鼠标的坐标
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。

Lv1.梦旅人

虱子

梦石
0
星屑
121
在线时间
1782 小时
注册时间
2010-6-19
帖子
3597
2
发表于 2012-7-18 22:10:45 | 只看该作者
首先你需要鼠标脚本,然后用
  1. @mouse_x,@mouse_y = Mouse.get_mouse_pos
复制代码
这样@mouse_x,@mouse_y就分别是鼠标在屏幕中的x和y值
这个指令一般在每个update里调用一次就可以了,因为在鼠标脚本里鼠标的坐标是每帧刷新一次的

评分

参与人数 1星屑 +60 收起 理由
hcm + 60 感谢回答

查看全部评分


http://rpg.blue/thread-175056-1-2.html
PVZ型塔防物一个
http://rpg.blue/thread-155199-1-2.html
RMXP技术讨论区手动认可帖,得到答案请认可
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
3
 楼主| 发表于 2012-7-19 09:07:06 | 只看该作者
Wind2010 发表于 2012-7-18 22:10
首先你需要鼠标脚本,然后用这样@mouse_x,@mouse_y就分别是鼠标在屏幕中的x和y值
这个指令一般在每个updat ...

这个MOUSE是的坐标在游戏里可以查看吗
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。
回复

使用道具 举报

Lv4.逐梦者

梦石
3
星屑
6420
在线时间
1131 小时
注册时间
2007-12-26
帖子
2402
4
发表于 2012-7-19 13:48:24 | 只看该作者
eu国猪 发表于 2012-7-19 09:07
这个MOUSE是的坐标在游戏里可以查看吗

在每一句     mouse_x, mouse_y = Mouse.get_mouse_pos  之下添加以下脚本,然后就可以在游戏中通过调用 $mouse_x, $mouse_y 查看了
  1.      $mouse_x = mouse_x
  2.      $mouse_y = mouse_y
复制代码
囡囚囨囚囨図囨囧
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
5
 楼主| 发表于 2012-7-19 17:50:23 | 只看该作者
幻耶 发表于 2012-7-19 13:48
在每一句     mouse_x, mouse_y = Mouse.get_mouse_pos  之下添加以下脚本,然后就可以在游戏中通过调用  ...

怎么通过调用查看$mouse_x, $mouse_y

点评

送进Scene的Update 如果非要看可以drawText到Window类中  发表于 2012-7-19 18:25
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
6
 楼主| 发表于 2012-7-19 18:58:16 | 只看该作者
eu国猪 发表于 2012-7-19 17:50
怎么通过调用查看$mouse_x, $mouse_y

drawText是什么意思
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。
回复

使用道具 举报

Lv1.梦旅人

昨日的黄昏

梦石
0
星屑
106
在线时间
936 小时
注册时间
2006-11-5
帖子
4128

第2届短篇游戏比赛季军第3届短篇游戏大赛小游戏及其他组季军

7
发表于 2012-7-19 19:04:15 | 只看该作者
eu国猪 发表于 2012-7-19 18:58
drawText是什么意思

= =Bitmap的draw_text方法啊,如果再窗口 不是self.contents.draw_text(x,y,w,h,$mouse_x.to_s)嘛……每次重新绘制一下这个窗口就好了,或者new Sprite用sprite的Bitmap对象绘制也一样

点评

你当别人程序员啊(:  发表于 2012-7-26 11:48
[url=http://weibo.com/2238291690?s=6uyXnP]
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
8
 楼主| 发表于 2012-7-19 19:07:45 | 只看该作者
本帖最后由 hcm 于 2012-8-6 09:23 编辑
七夕小雨 发表于 2012-7-19 19:04
= =Bitmap的draw_text方法啊,如果再窗口 不是self.contents.draw_text(x,y,w,h,$mouse_x.to_s)嘛……每 ...


麻烦你给我弄一个范例!!!我实在不懂
  1. #==============================================================================
  2. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  3. $敌人选框扩大 = 20
  4. $角色选框扩大 = 30

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

  458. #==============================================================================
  459. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  460. #============================================================================
复制代码
==
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
46
在线时间
223 小时
注册时间
2010-7-7
帖子
213
9
 楼主| 发表于 2012-7-19 19:09:56 | 只看该作者
eu国猪 发表于 2012-7-19 19:07
麻烦你给我弄一个范例!!!我实在不懂#==================================================== ...

以上是鼠标脚本
每天5小时制作游戏,5小时测试,把游戏都玩透了。晕,不知说了什么。。。。
回复

使用道具 举报

Lv1.梦旅人

昨日的黄昏

梦石
0
星屑
106
在线时间
936 小时
注册时间
2006-11-5
帖子
4128

第2届短篇游戏比赛季军第3届短篇游戏大赛小游戏及其他组季军

10
发表于 2012-7-19 19:21:39 | 只看该作者
本帖最后由 七夕小雨 于 2012-7-19 19:24 编辑

不用这样劳师动众都贴上来   mouseX,mouseY = Mouse.get_mouse_pos这个是获得的方法


那么在Scene_Map中main入口添加如下代码

@sprietMousePos = Sprite.new
@sprietMousePos.bitmap = Bitmap.new(200,100)

然后在update中添加
mouseX,mouseY = Mouse.get_mouse_pos
@sprietMousePos.bitmap.clear
@sprietMousePos.bitmap.draw_text(0,0,100,32,mouseX.to_S)
@sprietMousePos.bitmap.draw_text(0,32,100,32,mouseY.to_S)



这样,晃动鼠标就会随时看到鼠标的坐标

评分

参与人数 1星屑 +100 收起 理由
hcm + 100 感谢回答

查看全部评分

[url=http://weibo.com/2238291690?s=6uyXnP]
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-25 23:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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