Zooming and scrolling in SpriteKit

Here is my solution to the scrolling problem. It revolves around “stealing” the behaviour from the UIScrollView. I learned this from a WWDC Video from 2012 about mixing UIKit with OpenGL. Add the UIScrollViewDelegate methods to your ViewController and set the scroll view delegate to the ViewController Add/Move the PanGestureRecognizer from the UIScrollView to the … Read more

SpriteKit physics in Swift – Ball slides against wall instead of reflecting

This appears to be an issue with collision detection. Most have found solutions by using the didBeginContact and reapplying the force at an opposite direction. Note he says didMoveToView but corrects himself in a later comment to didBeginContact. See comments at the bottom of the Ray Wenderlich tutorial here I have a fix for the … Read more

How can I make a function execute every second in swift?

You can use one like this: var timer = NSTimer() override func viewDidLoad() { scheduledTimerWithTimeInterval() } func scheduledTimerWithTimeInterval(){ // Scheduling timer to Call the function “updateCounting” with the interval of 1 seconds timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector(“updateCounting”), userInfo: nil, repeats: true) } func updateCounting(){ NSLog(“counting..”) } Swift 3: var timer = Timer() override … Read more

Attack button in SpriteKit

I’ve writen a small ‘starter’ project that demonstrates in a simple way (I hope) a lot of the concepts – just drop the code into a new project and run : Here is a simple Sprite-Kit GameScene.swift. Create a new, empty SpriteKit project and replace the GameScene.swift with this. Then build and run. Click on … Read more