动画跳过多个触摸输入

时间:2013-11-18 23:06:49

标签: javascript jquery html mobile-safari greensock

我正在编写一款专为平板电脑设计的HTML游戏,使用greensock作为动画引擎,使用jQuery进行事件绑定。可以在http://gregbatha.com/battleblocks/看到当前版本。它的工作原理是将每个块作为接收触摸事件的div并使用greensock移动。

它总体上运作良好,但是因为它是两个玩家,所以在任何给定时间都有两个人快速敲击障碍物。当两个人在几毫秒内相互敲击时,会导致动画滞后或跳过。有谁知道这是为什么?

我的事件处理代码可以在下面看到

$('.block').bind( touchEnd, function(){
    $this = $(this);
    var thisX = $this.data('x');
    var thisY = $this.data('y');

    console.log(thisX+", "+thisY);

    var player = grid[thisY][thisX].player;

    //if this player currently hasn't selected any blocks, select this one
    if(players[player].selectedBlock == null && !$this.hasClass('group')){
        //set this block as the currently selected block
        selectBlock(thisX, thisY);

    }else{
        //otherwise react accordingly

        //if the player selected a selectable block, switch the currently selected block with this new one
        if($this.hasClass('group')){
            explodeGroup(thisX, thisY);
        }else if($this.hasClass('selectable')){
            $('.player'+player).removeClass('selected selectable');
            switchBlocks(players[player].selectedBlock.x, players[player].selectedBlock.y, thisX, thisY, function(){
                checkGroups();
            });
            players[player].selectedBlock = null;


        }else if($this.hasClass('selected')){
            //if player selects currently selected block, unselect it
            $('.player'+player).removeClass('selected selectable');
            players[player].selectedBlock = null;
        }else{
            //if the player did not select a selectable block for switching, make this new block the selected one
            $('.player'+player).removeClass('selected selectable');
            selectBlock(thisX, thisY);
        }
    }

} );

0 个答案:

没有答案