2017-09-01 114 views
1

我做了兩個按鈕(leftBtn和rightBtn)。當按下並按下時,它們工作得很好。但是,當您按住時,然後將手指從按鈕上移開並按下,按鈕保持不動?SpriteKit按鈕保持按下

這裏是兩個觸的代碼,並觸

func touchDown(atPoint pos : CGPoint) { 
    let rightBtn = childNode(withName: "rightBtn"); 
    let leftBtn = childNode(withName: "leftBtn"); 

    if(rightBtn?.frame.contains(pos) == true){ 
     right = true; 
    } 
    else if(leftBtn?.frame.contains(pos) == true){ 
     left = true; 
    } 
} 

func touchMoved(toPoint pos : CGPoint) { 

} 

func touchUp(atPoint pos : CGPoint) { 
    let rightBtn = childNode(withName: "rightBtn"); 
    let leftBtn = childNode(withName: "leftBtn"); 

    if(rightBtn?.frame.contains(pos) == true){ 
     right = false; 
     carController.stopMove(); 
    } 
    else if(leftBtn?.frame.contains(pos) == true){ 
     left = false; 
     carController.stopMove(); 
    } 
} 

回答

1

按鈕停留下來,因爲在觸摸向上(即手指向上移動並遠離屏幕)上的按鈕不會發生了。相反,它發生在你的觀點的其他部分。如果你想讓按鈕不被按下,可以考慮在touchesMoved方法中添加代碼。