创建一个愤怒的小鸟类型的项目,我使球在目标上飞行,并且在碰撞后目标消失了,但是即使在将球从子视图中移除后,当球在目标框架中时,得分也不断提高。
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)"
答案 0 :(得分:0)
一种方法可能是检查敌人1视图是否仍然存在:
collisionBehaviour.action = {
if enemy1.superview != nil {
//your code
for boulderView in self.bouldersArray {
}
}
}