how to access entity from code - gameplay kit

I have a node I added in the scene. Also in the scene I give it a component to bounce. The component looks like this: class BounceComponent: GKComponent, ComponentSetupProt { var bounce: SKAction? var node: SKSpriteNode? @GKInspectable var diff: C...
more »

2017-09-30 03:09 (1) Answers

Understanding SpriteKit CollisionBitMask

I am learning to use SpriteKit and I am following a tutorial for colllisions. I am struggling to understand the following code: struct PhysicsCategory { static let None : UInt32 = 0 static let All : UInt32 = UInt32.max static let Mo...
more »

2017-09-29 20:09 (2) Answers

moving platform with gameplay kit

Creating a 2d game, and want to add moving platforms where I can control the pattern and rotation of the platform. Example: I want this platform to move in a clockwise motion, also when it reaches the top and bottom I want it to rotate accordingl...
more »

2017-09-26 18:09 (1) Answers

Trouble creating a polygon path

I'm having trouble creating a polygon path for a physicsbody. I'm loading a plist that contains an array of points for the path. In the image below I have blue dots visualising where the points from the plist are located to create the path. You can ...
more »

2017-09-24 07:09 (0) Answers

SKScene doesn't deinit

I encountered a big problem to my application. My MainMenu scene doesn't deallocate when I transition to a new one. //GameViewController override func viewDidLoad() { super.viewDidLoad() if let view = self.view as! SKView? { // Loa...
more »

2017-09-23 17:09 (2) Answers

SKAction wait interval NOT consistent

I have a function that creates SpriteNode copies and move each copy along a rectangle path at a specified interval. I have a problem with this interval that the action is executed at inconsistent interval making odd gaps between sprite nodes while a...
more »

2017-09-23 07:09 (1) Answers

Move object while holding button in Swift

I have a little Space Invaders game and I added two buttons leftButton and rightButton and I want the ship to move as long as one of the buttons is touched AND HELD in the proper direction. I made it move in the right direction but I have to tap the...
more »

2017-09-20 18:09 (1) Answers

Spritekit Changing Gravity

I've been trying to be able to alter gravity by using override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { self.physicsWorld.gravity = CGVector(dx: 0, dy: 0) } but that doesn't seem to change the gravity at all. When ...
more »

2017-09-17 02:09 (1) Answers

SpriteKit increasing speed of move action

I have a simple game that two lines moving from top to bottom of the screen. There is a fixed space between those two lines and a ball has to pass through in that space otherwise game is over. I have no problem with the basics of the game, I can ad...
more »

2017-09-13 13:09 (1) Answers

Best way to "eat" something in SpriteKit

By "eat" I mean: when sprite A (Mario) collides with sprite B (a coin) the collision is detected and the coin is removed from the scene; however, Mario's movement is not altered by the collision with the coin. At the moment I'm using SKPhysicsContac...
more »

2017-09-12 00:09 (2) Answers

Randomly generating two nodes

I am creating a mobile application in Swift 3's SpriteKit. I am trying to create two rocks that a character has to dodge. I have the random generation working with -> func createTopRock(){ var topRockChoice = [SKTexture(image: #imageLiteral(reso...
more »

2017-09-08 17:09 (2) Answers

swift animate spritekit with damping effect

I've been searching on the internet for several days, I didn't find what I'm looking for. I'm working on an iOS game and I would like to move some sprites using usingSpringWithDamping (to have some rubber effect when moving my sprites). I have found...
more »

2017-09-07 21:09 (2) Answers

How to change SpriteKit's coordinate system

All SKSpriteNodes have their origin, also called anchorPoint, if I'm not wrong, in their middle. I want to translate that origin to be in the middle of the top line of the node. I've tried the following inside the init() method, but it doesn't work: ...
more »

2017-09-04 10:09 (1) Answers

Randomly spawning nodes

class GameScene: SKScene { let balls = [ SKSpriteNode(imageNamed: "blueball.png"), SKSpriteNode(imageNamed: "greenball.png"), SKSpriteNode(imageNamed: "realredball.png"), ] override func didMove(to view: SKView) { spawnBalls() } ...
more »

2017-08-31 22:08 (1) Answers

Adding a background to a SKLabelNode

I have been trying to add a background around my SKLabelNode, but I can't figure out how to do it programmatically in swift 3. I see some old posts that use .background, but that doesn't work for me. let background = SKSpriteNode(color: UIColor.whit...
more »

2017-08-26 20:08 (1) Answers

Delay function in SpriteKit (Swift 3) not working

After looking at several other questions like this, all the answers from their questions are not working for me. I have a pause label, and when the user presses play, I want the label to go from "Paused" to countdown from 3 to 1. I've declared the ...
more »

2017-08-23 15:08 (2) Answers

Detect if collision occurred between 2 objects

I started studying the Sprite Kit Game in iOS and I am want to find out how can I detect if a collision occurred when the ball entered in the hoop. To make things easier to understand. My at my basketball hoop I have 2 corners (they are red and easy...
more »

2017-08-21 15:08 (2) Answers

Comparing SpriteKit textures

if animal.texture == SKTexture(imageNamed: "cowTexture") { //do stuff } Apparently, the second half of my if statement above is creating a new texture which means the condition is never true. I did come across an answer to this problem using an ...
more »

2017-08-19 04:08 (1) Answers

Swift & SpriteKit - switch statement using break

I have a switch statement that that determines which node name was touched. I have two nodes that overlap. If the top one is touched, I want only the code for the top node case to be executed. So I put a break after that case. Even so, the code for b...
more »

2017-08-13 22:08 (1) Answers