我的游戏使用 PanDetector 来移动玩家。
class MyGame extends BaseGame with PanDetector, HasTapableComponents {
@override
void onPanUpdate(DragUpdateDetails details) {
// move the player
player.move(details.delta.dx, details.delta.dy);
super.onPanUpdate(details);
}
}
我需要在屏幕的右上角添加一个暂停按钮。
class PauseComponent extends PositionComponent with Tapable, HasGameRef<MyGame>{
Rect rect;
Sprite spritePause = Sprite("pause_button.png");
PauseComponent(){
rect = Rect.fromLTWH(
Get.find<Config>().screenSize.width * 0.92,
Get.find<Config>().screenSize.height * 0.04,
Get.find<Config>().screenSize.width * 0.05,
Get.find<Config>().screenSize.height * 0.10);
}
@override
void render(Canvas c) {
spritePause.renderRect(c, rect);
}
@override
void onTapDown(TapDownDetails details) {
if(gameRef.gameState == GameState.PLAYING){
gameRef.gameState = GameState.PAUSED;
gameRef.pauseEngine();
} else {
gameRef.gameState = GameState.PLAYING;
gameRef.resumeEngine();
}
print("STATUS: ${gameRef.gameState}");
super.onTapDown(details);
}
}
但它不工作,我怎样才能让 PauseComponent 的 onTapDown 工作,使用 PanDetector 和其他一些 Detector 到 PauseComponent?