查看: 5071|回复: 15

使用脚本变量解决鼠标与键盘抢光标的效果

  [复制链接]
梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-8-10
回帖
213
发表于 2008-9-23 16:54:22 | 显示全部楼层 |阅读模式

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

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

×
最近正在筹备制作一个带有鼠标的游戏!发现每个鼠标脚本都会跟键盘抢光标,就算鼠标不移动的时候也是如此!所以本人现在找了个鼠标脚本来开刀!修改后脚本大概如下!

首先是定义一个变量判断鼠标是否是移动中状态

#鼠标是否移动
$mouse_move


然后判断鼠标是否是静止状态(这里要借助鼠标无动作淡出的脚本)

  if @mouse_sprite != nil
     if @old_x != @mouse_sprite.x or @old_y != @mouse_sprite.y or
       Mouse.press?(Mouse::LEFT) or
       Mouse.press?(Mouse::RIGHT)
       @waittime = 80
       @mouse_sprite.opacity = 255
       ###########
       $mouse_move = true
       ###########

     end
     @waittime -= 1 if @waittime != 0
     @mouse_sprite.opacity -= 8 if @waittime == 0 and @mouse_sprite.opacity > 0
     @old_x = @mouse_sprite.x
     @old_y = @mouse_sprite.y
      ###########
      if @mouse_sprite.opacity < 100 or @waittime < 40   #这里是用透明度或者等待时间来判断鼠标是否正在使用中
        $mouse_move = false
      end
      ###########
  end

最后将所有有 update_cursor_rect和 mouse_not_in_rect 的脚本后面都加个判断,鼠标不移动就不刷新,其中 tp_index = @index 是将光标赋值到鼠标,也就是鼠标抢光标的罪魁祸首- -,可是这条语句又不能完全不用!所以也在后面加个判断就OK!不然鼠标就不是抢当前光标了!而是抢当前以外的光标!那就更郁闷了!- -


class Window_Selectable
if @self_alias == nil
   alias self_update update
   @self_alias = true
end
def update
   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 if $mouse_move#####
       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 $mouse_move#####
         if tp_index != @index
           tp_index = @index if $mouse_move#####
           $game_system.se_play($data_system.cursor_se)
         end
         break
       end
     end
     if mouse_not_in_rect
       @index = index_var
       update_cursor_rect if $mouse_move#####
       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_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 if $mouse_move#####
       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 $mouse_move#####
         break
       end
     end
     if mouse_not_in_rect
       @index = index_var
       update_cursor_rect if $mouse_move#####
       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_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 if $mouse_move#####
       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 if $mouse_move#####
         break
       end
     end
     if mouse_not_in_rect
       @index = index_var
       update_cursor_rect if $mouse_move#####
       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

然后就OK了!所有的修改大致如此!以下是脚本(本人借用了鼠标无动作淡出来开刀的,大致上不会出现BUG或冲突)

下载地址(范例工程就不用了,反正只有一处脚本,直接插入Main之前就行)
http://rpg.blue/upload_program/g ... …‰标_102588784.txt
哎!要完成这个游戏肯定要使用很多脚本和素材!我想把小樱的动画变成游戏!我相信这并不是不可能的事!
梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-8-10
回帖
213
 楼主| 发表于 2008-9-23 16:57:05 | 显示全部楼层
{/gg}发错区了!应该是RMXP的才对!请版主帮忙转移一下!谢谢!
哎!要完成这个游戏肯定要使用很多脚本和素材!我想把小樱的动画变成游戏!我相信这并不是不可能的事!
回复

使用道具 举报

梦石
0
星屑
50
在线时间
1 小时
注册时间
2008-8-3
回帖
947
发表于 2008-9-23 17:33:38 | 显示全部楼层
支持下……


很期待LZ签名中的游戏{/hx},嗯嗯
回复

使用道具 举报

天仙

梦石
0
星屑
720
在线时间
184 小时
注册时间
2008-4-15
回帖
4872

贵宾

发表于 2008-9-23 18:54:57 | 显示全部楼层
以下引用果冻叮当猫于2008-9-23 8:57:05的发言:
发错区了!应该是RMXP的才对!请版主帮忙转移一下!谢谢!

转移完毕
VA脚本开工中...
偷窃脚本1.0 - 已完成
回复

使用道具 举报

青天

梦石
0
星屑
86
在线时间
232 小时
注册时间
2007-12-15
回帖
2013

开拓者

发表于 2008-9-23 19:00:38 | 显示全部楼层
很好,期待了很久的啊!
开坑准备中
回复

使用道具 举报

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2008-9-23 21:19:39 | 显示全部楼层
貌似不错 曾经想做鼠标嫌麻烦{/gg}
回复

使用道具 举报

梦石
0
星屑
50
在线时间
0 小时
注册时间
2008-4-29
回帖
76
发表于 2008-9-24 04:48:32 | 显示全部楼层
效果不错!还可以!不过在鼠标没用的时候键盘按键移动到鼠标的位置(鼠标隐藏)还是有小小的延时!不过问题还不大!至少不用牺牲FPS值!
遇到喜欢的东西就要去做!喜欢魔卡少女樱,所以喜欢她的所有,也喜欢自己为她做的游戏!喜欢的人一起来吧!(QQ:302157370)
回复

使用道具 举报

梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-8-10
回帖
213
 楼主| 发表于 2008-9-25 04:46:11 | 显示全部楼层
暂时没发现什么大错误!还算过得去
哎!要完成这个游戏肯定要使用很多脚本和素材!我想把小樱的动画变成游戏!我相信这并不是不可能的事!
回复

使用道具 举报

梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-8-10
回帖
213
 楼主| 发表于 2008-9-25 04:54:26 | 显示全部楼层
发现一个问题!鼠标停留在光标位置不动后使用键盘移动到改鼠标位置有奇怪的连续响声!
解决办法:

         if tp_index != @index and $mouse_move#####
           tp_index = @index #if $mouse_move#####
           $game_system.se_play($data_system.cursor_se)
         end

找到下列脚本改成这样就可以了!
毕竟是简单的问题就不做解释了哈!{/kuk}
哎!要完成这个游戏肯定要使用很多脚本和素材!我想把小樱的动画变成游戏!我相信这并不是不可能的事!
回复

使用道具 举报

梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-8-10
回帖
213
 楼主| 发表于 2008-9-29 06:23:46 | 显示全部楼层
用了很久了!完全找不到有什么BUG!请大家帮忙找一下哈!
哎!要完成这个游戏肯定要使用很多脚本和素材!我想把小樱的动画变成游戏!我相信这并不是不可能的事!
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部