gpt4 book ai didi

xcode - “再玩一次”按钮无法正常工作

转载 作者:行者123 更新时间:2023-11-30 13:40:16 24 4
gpt4 key购买 nike

我在游戏中制作了一个重玩按钮,并使用SKTransition重新启动游戏。当我触摸“再次播放”按钮时,新场景就会出现。但这个场景的物体比上一个场景的物体大。场景被卡住了。当我触摸“再次玩”按钮时,我无法玩游戏。我应该怎么办?这是我关于按钮和重新启动场景的所有代码:

let playAgain: UIButton = UIButton(frame: CGRectMake(10, 0, 450, 1000))

class GameScene: SKScene {
func buttonPressed(sender: UIButton) {
let pransition = SKTransition.fadeWithDuration(1.0) //create a transition
let gamePlayScene = GameScene(fileNamed: "GameScene") // create a new scene from your file (let variableName = NameOfGameFile(fileNamed: "NameOfGameFile")
self.view?.presentScene(gamePlayScene!, transition: pransition) // present the scene with the transition
}



override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch:AnyObject in touches{...



if(..){...}
else{
playAgain.setTitle("Play Again", forState: UIControlState.Normal)
playAgain.titleLabel!.font = UIFont(name: "Helvetica", size: 50)

playAgain.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside)
playAgain.tag = 1
self.view!.addSubview(playAgain)

最佳答案

您的问题是,当您通过播放按钮创建到游戏场景的过渡时,您没有设置场景大小。我刚刚插入了你的代码,它就按照你说的做了。快速地,在创建过渡时设置场景的大小和纵横比是一个很好的做法,比如说回到游戏或从游戏到结束场景,例如获胜场景或宽松场景等。简单的方法是是在声明游戏场景常量后添加场景长宽比,如下代码块:

let pransition = SKTransition.fadeWithDuration(1.0)
let gamePlayScene = GameScene(fileNamed: "GameScene")
gamePlayScene!.scaleMode = SKSceneScaleMode.AspectFill
self.view?.presentScene(gamePlayScene!, transition: transition)
self.playAgain.removeFromSuperview()

我通常喜欢为游戏的戏剧性方面创建等待一两秒的时间,因此我使用以下内容,这与您所做的非常相似,但在场景触发之前会产生一些延迟,以下是我用的,如果你愿意的话可以随意更改。

let wait = SKAction.waitForDuration(1.5)
let theGameScene = GameScene(size: self.size)
theGameScene.scaleMode = SKSceneScaleMode.AspectFill
let theTransition = SKTransition.fadeWithDuration(1.0)
let changeScene = SKAction.runBlock{
self.scene?.view?.presentScene(theGameScene, transition: theTransition)
}

let sequence = SKAction.sequence([wait, changeScene])
self.runAction(SKAction.repeatAction(sequence, count: 1))

祝你好运,继续编码并提出问题。

关于xcode - “再玩一次”按钮无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35657330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com