I'm a newbie with Swift - after searching so much hours, I need help from you professionals :D
Planing a small IOS App with Swift, this is the structure:
- GameViewcontroller
- GameScene
In GameScene, I placed a little image:
class GameScene: SKScene {
private var tanzschuhR: SKSpriteNode!
override func didMove(to view: SKView) {
self.size = CGSize(width: 1024, height: 1024)
self.backgroundColor = .gray
self.scaleMode = .aspectFill
let startPt = CGPoint(x: 500, y: 400)
tanzschuhR = SKSpriteNode(imageNamed: `SchuhR`)
tanzschuhR.position = startPt
tanzschuhR.zPosition = 1
self.addChild(tanzschuhR)
func swingPattern1() {
// move it
let negDelta = CGVector(dx: -50, dy: -50)
let action = SKAction.move(by: negDelta, duration: 4)
tanzschuhR.run(action)
}
}
}
For now, I just want to start the function swingPattern1() from a IBAction Button in the GameViewController, in order to start the movement of the image synchron to the audio is playing.
This is the part of the button:
@IBAction func playIt(_ sender: UIButton) {
playMultipleSound()
// no idea to call the function swingPattern1()
// always get an error
}
So, could anyone help me?
How to call this function, if the button is tapped?
Or is there another, better way to start audio an the movement by tapping a button?
Many thanks for your help...
UPDATE:
I placed the var in the IBAction:
@IBAction func playIt(_ sender: UIButton) {
playMultipleSound()
let gameScene = GameScene()
gameScene.swingPattern1()
}
Don't know,if it's the right syntax - sorry... :D
After BUILD&RUN, I get this error:
The app stopps...