创建一个愤怒的小鸟类型的项目,我让球飞向目标,碰撞后目标消失,但当球位于目标框架中时,即使从 subview 中删除,分数也会持续上升。
let enemy1 = UIImageView(image: nil)
enemy1.image = UIImage(named: "enemy2.png")
enemy1.frame = CGRect(x: w*0.85, y: h*0.035, width: w*0.12, height: h*0.22)
self.view.addSubview(enemy1)
collisionBehaviour.action = {
for boulderView in self.bouldersArray{
if boulderView.frame.intersects(enemy1.frame){
enemy1.removeFromSuperview()
self.scoreCount += 1
self.scoreCountLabel.text = "Score: \(self.scoreCount)"
最佳答案
一种方法可能是检查敌人1 View 是否仍然存在:
collisionBehaviour.action = {
if enemy1.superview != nil {
//your code
for boulderView in self.bouldersArray {
}
}
}
关于ios - 碰撞后如何阻止分数增加一以上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59391850/