I know that's likely a stupid question, but I'm trying for several hours already and can't do it. So, I'm making a simple game. I have 4 functions for death of my hero. Each of them is performing a different animation so I want program to know who exactly killed a hero. My logic is to put that functions into the array but Xcode tells me that I have a "missing argument for parameter #1 in call". I ignored that and tried to make a switch statement. But every 'case' has an error that tells me that it's expecting a pattern. Here is my code:
func didBeginContact(contact: SKPhysicsContact) {
dead()
}
var deathArray:Array = [eatenByMouse(), eatenByCat(), eatenByHamster(), eatenByRabbit()]
func dead() {
switch deathArray {
case :
eatenByMouse()
case:
eatenByCat()
case:
eatenByHamster()
case:
eatenByRabbit()
default:
cookie
}
}
It's probably an extremely simple problem but I'm new to this and don't know what to do.
I think it's a good idea to post more related samples of my code. I think, my problem could be in collisions. So I have a ColliderType:
enum ColliderType:UInt32 {
case Cookie = 1
case Rabbit = 2
case Mouse = 3
case Hamster = 4
case Cat = 5
}
Then I'm making a physic bodies for hero and enemies:
self.cookie.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(self.cookie.size.width / 2))
self.cookie.physicsBody?.affectedByGravity = false
self.cookie.physicsBody?.categoryBitMask = ColliderType.Cookie.rawValue
self.cookie.physicsBody?.collisionBitMask = ColliderType.Mouse.rawValue
self.cookie.physicsBody?.contactTestBitMask = ColliderType.Mouse.rawValue
self.mouse.physicsBody = SKPhysicsBody(rectangleOfSize: self.mouse.size)
self.mouse.physicsBody?.dynamic = false
self.mouse.physicsBody?.categoryBitMask = ColliderType.Mouse.rawValue
self.mouse.physicsBody?.contactTestBitMask = ColliderType.Cookie.rawValue
self.mouse.physicsBody?.collisionBitMask = ColliderType.Cookie.rawValue
Sample of eatenByMouse() function:
func eatenByMouse() {
self.groundSpeed = 0
self.cookie.hidden = true
let animateAction = SKAction.animateWithTextures(self.mouseArray, timePerFrame: 0.1)
self.mouse.runAction(animateAction)
}
I hope it will clear something maybe. It seems to be so easy problem, I'm ashamed that I don't understand it.
switch deathArraydoes not look right to me (actually the wholeswitchstatement looks funny). It looks like you want to provide an index into thedeathArrayto run the corresponding action, but I don't see any reference to an index value.