gpt4 book ai didi

ios - 快速更改播放器

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

我正在游戏中工作,遇到一个问题,我设置了两个按钮,当我单击第一个按钮时,它会生成第一个玩家,当我单击第二个按钮时,它会删除第一个玩家并生成第二个玩家和所有东西这很好,但问题是当我单击第一个按钮时,它只会生成一个节点。

如何让它生成一个节点,然后当我单击不生成电话时,我单击另一个按钮,第二个按钮也是如此,这是我的代码帮助,请..

// Set button One

ButtoneOne = UIButton(frame: CGRect(x: 0, y: 0, width: frame.size.width / 25, height: frame.size.height / 20))
ButtoneOne.center = CGPoint(x: view.frame.size.width / 6.5, y: view.frame.size.height / 2)
ButtoneOne.setImage(ButtonTextureOne, forState: .Normal)
ButtoneOne.addTarget(self, action: #selector(Play.PlayesrOne), forControlEvents: UIControlEvents.TouchUpInside)
self.view?.addSubview(ButtoneOne)

func PlayesrOne() {

Player.removeFromParent()
PlayerTwo.removeFromParent()

PlayerOne = SKSpriteNode(imageNamed: "PlayerOne")
PlayerOne.size = CGSize(width: 150, height: 200)
PlayerOne.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
PlayerOne.zPosition = -1
self.addChild(PlayerOne)


}

最佳答案

请记住,在 iOS 中(不仅是在 iOS 中),将属性大写是一种不好的态度。

我不想重构你的所有代码,我会尽力维护你的结构和方法:

buttoneOne = UIButton(frame: CGRect(x: 0, y: 0, width: frame.size.width / 25, height: frame.size.height / 20))
buttoneOne.center = CGPoint(x: view.frame.size.width / 6.5, y: view.frame.size.height / 2)
buttoneOne.setImage(ButtonTextureOne, forState: .Normal)
buttoneOne.addTarget(self, action: #selector(Play.PlayesrOne), forControlEvents: UIControlEvents.TouchUpInside)
self.view?.addSubview(buttoneOne)

func makePlayerOne() {
if (self.childNodeWithName("playerOne") == nil) {
playerOne = SKSpriteNode(imageNamed: "PlayerOne")
playerOne.size = CGSize(width: 150, height: 200)
playerOne.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
playerOne.zPosition = -1
playerOne.name = "playerOne"
self.addChild(playerOne)
}
}

func PlayesrOne() {
player.removeFromParent()
playerOne.removeFromParent()
playerTwo.removeFromParent()
makePlayerOne()
}

你可以为player2的spawn做同样的事情..

关于ios - 快速更改播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38658636/

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