我想设置一个计数器,每当两个特定物体碰撞时加1。这是我的代码:
@IBOutlet weak var Wall: UIImageView!
@IBOutlet weak var Player: UIImageView!
@IBOutlet weak var CountLabel: UILabel!
var CountNumber : Int!
func PlayerMoving() {
//The code for moving an object.
if (CGRectIntersectsRect(Player.frame, Wall.frame)){
Add()
}}
func Add() {
CountNumber = CountNumber + 1
CountLabel.text = "\(CountNumber)"
}
override func viewDidLoad() {
CountNumber = 0
//Timer for moving the Player
}
但是在它们发生碰撞之后,即使添加了1,场景也会刷新。就像玩家移动并撞到墙上一样,玩家会回到最初开始的地方。我希望它能够以相同的方向继续以相同的速度继续前进。感谢。