2014-08-30 74 views
1

嗨,我是新的網頁遊戲開發,並試圖建立紙牌遊戲使用Quintus遊戲引擎我有對象稱爲卡我可以觸摸並拖動它在屏幕上,但我只想觸摸並拖動它一次,但我可以「T弄清楚如何禁用觸摸後,我拖着卡和我嘗試谷歌,但沒有運氣我的代碼:如何在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; 

但不工作,所以任何幫助,如果你請提及任何sou對於Quintus文件或書籍或Quintus提前感謝任何良好的資源。如果你只想要一個精靈/元素

Q.untouch(); 

回答

2

如果你想完全禁用觸摸事件,添加此

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

我在哪裏找到的? Here