我对 AS3 还很陌生,我正在创建一个基于文本的游戏,但我很难从屏幕上清除文本。我正在使用 FlxText 和 FlxButtons。当我使用 clear() 时,它会删除所有内容。这是它的样子(对不起,如果这超出了我应该说的,我很着急,代码工作也可能很糟糕。):
public function DragonState()
{
FlxG.mouse.show();
menuButton = new FlxButton(240, 220, "Menu", menu);
add(menuButton);
swordButton = new FlxButton(0, 220, "Slash", sword);
add(swordButton)
shieldButton = new FlxButton(80, 220, "Sheild Bash", shield);
add(shieldButton)
bowButton = new FlxButton(160, 220, "Shoot", bow);
add(bowButton)
}
private function menu():void
{
FlxG.mouse.hide();
FlxG.switchState(new MenuState);
}
public function sword():void
{
playerAttack = Math.floor(Math.random() * (2 - 0 +2) * 7);
dragonAttack = Math.floor(Math.random() * (1 - 0 + 1) * 7);
add(new FlxText(0, 0, 320, "The Dragon hit you for " + String(dragonAttack)));
add(new FlxText(0, 10, 320, "You hit the Dragon for " + String(playerAttack)));
updateHealth()
}
public function shield():void
{
playerAttack = Math.floor(Math.random() * (2 - 0 +2) * 2);
dragonAttack = Math.floor(Math.random() * (1 - 0 + 1) * 2);
add(new FlxText(0, 0, 320, "The Dragon hit you for " + String(dragonAttack)));
add(new FlxText(0, 10, 320, "You hit the Dragon for " + String(playerAttack)));
updateHealth()
}
public function bow():void
{
playerAttack = Math.floor(Math.random() * (2 - 0 + 2) * 4);
dragonAttack = Math.floor(Math.random() * (2 - 0 + 2) * 4);
add(new FlxText(0, 0, 320, "The Dragon hit you for " + String(dragonAttack)));
add(new FlxText(0, 10, 320, "You hit the Dragon for " + String(playerAttack)));
updateHealth()
}
public function updateHealth():void
{
dragonHealth = dragonHealth - playerAttack
playerHealth = playerHealth - dragonAttack
add(new FlxText(0, 20, 320, "The Dragon has " + String(dragonHealth) + " health left."));
add(new FlxText(0, 30, 320, "You have " + String(playerHealth) + " health left."));
if (dragonHealth <= 0) {
add(new FlxText(0,0,320,"Good Job"));
}else if (playerHealth<=0) {
add(new FlxText(0,0,320,"Oh No!"));
} else {
add(new FlxText(0,0,320,"What will you do?"));
}
}