所以我一直在我的遊戲中使用CCPanZoomController,並且遇到類似的問題,但有很多不同的方面,比如當他們觸摸一個精靈時,我不想讓背景移動或者我當背景縮放時,想讓精靈不移動。所以我所做的就是製作方法來「關閉」那些我不想做出反應的圖層,並在其他圖層的動作完成後重新啓用它們。
我在每個圖層內創建了以下方法來禁用它或啓用它用於從不同的觸摸事件調用的觸摸。
// Public Method: Allows for disabling touch for this layer and re-enabling it
-(void)enableTouches:(BOOL)enable
{
// Check if the bool value is to enable or disable touches
if (enable) {
// Call for the removal of all touch locations in array in the CCLayerPanZoom instance
[_panZoomLayer removeTouchesFromArray];
// Call the touch dispatcher and add the CCLayerPanZoom back as a delegate for touches
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:_panZoomLayer priority:0];
CCLOG(@"PanZoomWrapperLayer:enableTouches - LayerPanZoom touches enabled");
} else {
// Call the touch dispatcher to remove the CCLayerPanZoom as a delegate to disable touches
[[CCTouchDispatcher sharedDispatcher] removeDelegate:_panZoomLayer];
CCLOG(@"PanZoomWrapperLayer:enableTouches - LayerPanZoom touches disabled");
}
}
感謝您的回覆,但是這並不是我真正想要的 - 我可能會在以後的遊戲中使用它! – Harry
沒問題。最後的筆記...我忘了包括我添加到CCPanZoomController類的方法的代碼來清空數組。這很簡單,但以防萬一,在這裏你去。 // Public Method:自定義方法,用於在禁用觸摸時臨時清除觸摸陣列,以便在重新啓用時正常工作。 - (void)removeTouchesFromArray { //刪除觸摸數組中的所有對象 [self.touches removeAllObjects]; } – XBXSlagHeap