iOS上的JQuery Mouseup [英] JQuery Mouseup on iOS

查看:111
本文介绍了iOS上的JQuery Mouseup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近添加了 jquery. mouse2touch.min.js 插件插入到我的游戏中,经过测试后,我遇到了问题.我的移动系统由两个div组成(一个将玩家向左移动,另一个将其向右移动),基本上,当您按住div时,玩家应该向一个方向移动,而当您放开时,他应该停下来.问题是,如果我按下时间太长然后放开,播放器不会停止.

I've recently added the jquery.mouse2touch.min.js plugin to my game, and after testing it out I ran into a problem. My movement system is made up of two divs (one to move the player left and one to move him right), basically when you press and hold the div, the player should move in one direction and when you let go, he should stop. The problem is that if I press down for too long and then let go, the player doesn't stop.

这是让他动弹的代码:

// iControl System
var $div = $('#character');

$('#ios-left').mousedown(function(){
   leftTimer = setInterval(function(){
       processWalk('left');
   },100);
}).mouseup(function(){
    $('#character').stop();
    clearInterval(leftTimer);
}).mouse2touch();

$('#ios-right').mousedown(function(){
    rightTimer = setInterval(function(){
       processWalk('right');
    },100);
}).mouseup(function(){
    $('#character').stop();
    clearInterval(rightTimer);
}).mouse2touch();

和一个小提琴: http://jsfiddle.net/gqfesrhw/

谢谢(如果有人认为这可能是mouse2touch插件的问题,我会接受其他建议)

Thanks (Also if anyone thinks that this may be a problem with the mouse2touch plugin, I'd be open to other suggestions)

推荐答案

工作小提琴 a>

Working Fiddle

计时器的问题,您应该在移动之前清除时间间隔.带有clearInterval(TimerWalk);的全局变量TimerWalk应该很有用.

The issue with timer, you should clear-time-interval before move. Your global variable TimerWalk with clearInterval(TimerWalk); should be useful.

这是代码段

$('#ios-left').mousedown(function () {
    clearInterval(TimerWalk);
    TimerWalk = setInterval(function () {
        processWalk('left');
    }, 100);
}).mouseup(function () {
    $div.stop();
    clearInterval(TimerWalk);
}).mouse2touch();

$('#ios-right').mousedown(function () {
    clearInterval(TimerWalk);
    TimerWalk = setInterval(function () {
        processWalk('right');
    }, 100);
}).mouseup(function () {
    $div.stop();
    clearInterval(TimerWalk);
}).mouse2touch();

这仅是正确移动的解决方法,您可能需要解决其他问题.

This is only fix for proper movement, you may need to address other issues.

这篇关于iOS上的JQuery Mouseup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆