如何在Quintus中禁用触摸?

时间:2014-08-30 11:59:59

标签: html input html5-canvas touch game-engine

您好我是网络游戏开发的新手,并尝试使用Quintus游戏引擎制作纸牌游戏我有一个名为卡的对象我可以触摸并将其拖动到屏幕上,但我只想触摸和拖动它一次,但我无法弄清楚如何在我拖动卡片后禁用触摸,我尝试谷歌它但我的代码没有运气:

Q.Sprite.extend("Card", {


init: function(p){

    this._super(p,{
        asset: "Queen_OF_Hearts.png",
        x: Q.el.width / 2,
        y: Q.el.height - 120
    });

   this.on("drag");
   this.on("touchEnd");
},

drag: function(touch) {
   this.p.dragging = true;
   this.p.x = touch.origX + touch.dx;
   this.p.y = touch.origY + touch.dy;
 },

touchEnd: function(touch) {
   this.p.dragging = false;
   // put a line on the screen if the card pass it put the card in the new position if not put the card in the orginal(old) postion
   if(touch.origY + touch.dy > Q.el.height - 200) { //define the line that the card should pass if the amount of draged > the screen line in Q.el.height - 200
       // put the card in the same old postion if is not pass the line
       this.p.x = touch.origX;
       this.p.y = touch.origY;

    } else {
        // put the card if it pass the line in the new postion  
        this.p.x = Q.el.width / 2;
        this.p.y = Q.el.height - 280;

    }
}
});

所以在touchEnd中的else语句中我试图做那样的事情

this.p.touch = false;

但是没有工作,所以任何帮助,如果你提前感谢Quintus文件或书籍的任何来源或Quintus的任何好资源。

1 个答案:

答案 0 :(得分:2)

如果要完全禁用触摸事件,请添加:

Q.untouch();

如果你只想要一个精灵/元素:

touchEnd: function(touch) {
    touch.obj.off('drag');
    touch.obj.off('touchEnd');
}

我在哪里找到这个? Here