FAQ Database Discussion Community


How do you apply one action to multiple Sprites in SpriteKit?

swift,sprite-kit,action
If I've got a dude at the top of my screen, and a dude who comes in later at the bottom, and I want them both to move to the left of the screen using my moveToLeftOfScreen action I've created, how do I do that? If I've got var moveToLeftOfScreen...

Random position func

ios,swift,sprite-kit
I have 2 objects (dvere1, dvere2) having their positions. How to set up random func that these two objects by pressing changed their position. I am a beginner Here is my code: var dvere1 = SKSpriteNode(imageNamed: "D") var dvere2 = SKSpriteNode(imageNamed: "D") override func didMoveToView(view: SKView) { backgroundColor = SKColor.whiteColor()...

Decreasing accelerometer's sensitivity

ios,swift,sprite-kit,accelerometer,core-motion
I am making a game which have a square that moves from left to right, and at first I was using applyForce to do so, but I didn't like the results because it was not sensitive enough. Then I changed to velocity: func motionSensorUpdate(currentTime: CFTimeInterval){ let square = childNodeWithName(ksquarename) as!...

Could not cast value of type 'UIView' (0x112484eb0) to 'SKView' (0x111646718)

ios,swift,sprite-kit,xcode7,xcode6.3.2
Could not cast value of type 'UIView' (0x112484eb0) to 'SKView' (0x111646718). I keep on getting this error. Can anyone help me because the line of code is there by default. I converted the SK game into the latest swift syntax using the xcode 7 beta. The compiler was missing a...

sprite kit : contact not working

ios,sprite-kit
I am trying to make one simple game and this problem happen first my paddle can touch the ball but now it cant do that and this code also should give me message or in simulator but it is not showing any idea? import SpriteKit class GameScene: SKScene , SKPhysicsContactDelegate{...

How to move a node from the different locations?

swift,sprite-kit
I want to move a tree node to the left firstly from the center of the screen and then from the right to the left corner. It should look like infinite amount of trees. I have no problem with first part. Here is the code: let tree = SKSpriteNode (imageNamed:...

Collision Detection with an NSMutable array of Objects

sprite-kit,nsmutablearray,collision-detection
I'm attempting to make a game with objects that bounce between the left and right walls of the screen until they reach the bottom. I create my objects inside these methods which stores the objects in an NSMutable array and is called when the game begins. -(void)createContent { self.backgroundColor =...

Wrong node removed when using removeFromParent in spritekit

sprite-kit
I want a node to be removed from parent after it makes contact with an object, but the node is spawned continuously, with multiples of the same node on the screen at once. The issue is, whenever the node makes contact and removeFromParent is called, it isn't removed, but another...

Swift Sprite Kit recreating SKSpriteNode`s

ios,swift,sprite-kit
Currently, I am working at a Sprite Kit game with Swift. On the Screen, at the beginning, there are 5 Platforms. They are all SKSpriteNode's with color, all looking exactly the same. As the Player moves, the bottom Platform moves out of the screen on the Y-Axis, and a new...

Start the transition after 5 seconds

swift,sprite-kit
Hello how to make the transition let transitionType = SKTransition.crossFadeWithDuration (2.0) started after 5 seconds? my code: let nextLevel = level2(size: size) nextLevel.scaleMode = scaleMode let transitionType = SKTransition.crossFadeWithDuration(2.0) view?.presentScene(nextLevel,transition: transitionType) ...

Creating a “smooth” flat surface from multiple blocks in Spritekit

swift,sprite-kit
I'm trying to write an iOS game with Spritekit and Swift and this is my first question on stackoverflow :) To simplify my problem and my constraints, let's say I have two rectangle SKShapeNodes (my level) with the same height which are completely side by side, with physics bodies but...

Dragging and flicking/throwing skspritenode [duplicate]

ios,swift,sprite-kit
This question already has an answer here: how to throw SKSpriteNode? 2 answers I have ball sprite that i want to be able to flick towards other sprites. Right now, I have the function TouchesMoved below, but it moves my sprite towards any touch movement on the screen, when...

How to check if two CGVectors are equal in Objective-C?

objective-c,sprite-kit
I have two CGVectors: CGVector vector1 = CGVectorMake(1,2); CGVector vector2 = CGVectorMake(1,2); How can I check if vector1 is equal to vector2?...

Add SKShapeNode in another one

swift,sprite-kit,skshapenode
I want to draw a square in another square; but I can't position the second one in the right way. What can I do for positioning based on first square coordinates? var tileBackground = SKShapeNode(rectOfSize: CGSize(width: screenWidth, height: screenWidth)) tileBackground.name = "tileBackground" tileBackground.fillColor = SKColor.whiteColor() tileBackground.position = CGPoint(x: frame.midX, y:...

Sprite Kit: can not see existing node's children

swift,sprite-kit,nodes
I'm building a game with SpriteKit. This is my node tree: self.world.hydraAnchor.head The problem is that head can not be seen The code is simple let world = SKSpriteNode() addChild(world) ... let hydraAnchor = SKSpriteNode() hydraAnchor.position = anchorsPosition world.addChild(hydraAnchor) let head = SKSpriteNode(imageNamed: "hydraHead") head.position = CGPointMake(anchorsPosition.x, anchorsPosition.y + 50)...

Binary operator '-=' cannot be applied to operends of type 'CGFloat' and 'Int'

ios,swift,sprite-kit
I am currently making an app using Swift by following a tutorial. When I run the code in XCode, I get the error stated in the title. Here is my code: import SpriteKit class GameScene: SKScene { var currentLevel = 0 var currentLevelData:NSDictionary var levels:Levels var bg:SKSpriteNode var man:SKSpriteNode var...

Spritekit animation doesn't work in iOS7 but does in iOS8

objective-c,sprite-kit,skaction
I made a game to teach kids how to count. When you tap the right number it explodes and the next one starts to have a glowing animation as a tip. A while ago I noticed that this specific animation doesn't work in iOS7. This is how it looks like:...

How to update waitForDuration constant?

ios,sprite-kit,skaction
I have a flashing light that uses a SKAction sequence that hides and unhides a circle node. I want to be able to change the intervals at which it flashes based on two buttons. I declared a variable stdTime and I change it in the touchesBegan method but it's not...

Not allowed to use property observer

swift,properties,sprite-kit
I want two SKSpriteNodes to be at the same position and static to each other. I first tried setting this up in the update() function. sprite1.position = sprite2.position It gives sprite1 the position of sprite2 one frame before. With high speeds (changes in sprite2's position ) it gets clear they...

Swift multiple level scenes

ios,swift,sprite-kit
I am trying to work on a new game project where I will include multiple levels. I was reading this question (Sprite Kit - Defining the variables for multiple scenes) about the best way to do multiples scenes with as little duplicate code as possible. The answer of course is...

Action after tweet has been published

ios,twitter,sprite-kit
I set a button in my game where you can tweet your score. The thing is that when the user just publishes the tweet I want to open a new view and I don't know how to know when the tweet has been published. For publish the tweet I used...

Getting child SKSpriteNode Position

swift,sprite-kit
I am currently attempting to create a game that will auto generate platforms on the scene when a platform leaves the scene. I have created 5 SKSpriteNodes and added them as children to a Platform SKNode. I then move them accross the screen with platformGroupNode.position.x-- inside my update function However,...

SpriteKit: I'd need something like .pauseActionForKey()?

swift,sprite-kit,skaction
I'm a bit stuck at how to approach the following issue: My scrolling game spawns obstacles of different kinds that are loaded from a plist. The spawning is delayed by an SKAction, the duration of which for each obstacle is computed by the y position. Updated to reflect Wraithseeker's answer....

Resetting and changing speed on SKActions

swift,sprite-kit,velocity,skaction
Is there a way to change the velocity/speed of a skaction and also to reset the skaction? let wait = SKAction.waitForDuration(5.0) let moveRight = SKAction.moveByX(300, y:0, duration: 1.0) let sequence = SKAction.sequence([wait, moveRight]) let endlessAction = SKAction.repeatActionForever(sequence) node.runAction(endlessAction) This code works but the things i would like to change is...

What am i doing wrong when I switch scenes?

swift,sprite-kit
I am developing a game on sprite kit, and when the player loses they are taken to the EndScene and giving the option to play again. The problem I am having is when the player presses the button to play again they are taken to the GameScene, but instead the...

Swift Sprite Kit Camera Movement

ios,swift,camera,sprite-kit
I made a Camera in Sprite Kit focusing on a SKSpriteNode. There is a great Document by Apple: Apple Document However, the camera as it now is follows the SKSpriteNode immediately, while I want to have a little leeway. For e.g. the SKSpriteNode moves up and down after a touch...

Sprite Kit SKTexture animation height unexpectedly changing

ios,animation,sprite-kit,sktexture,sktextureatlas
I am using a SKTextureAtlas to animate a SKSpriteNode. The animation works, but it looks weird because for some reason the sprite's height is changing several times in the animation. This also causes the y position to change as well. Everything else remains the same except for the height and...

Sequence Action With EnumerateChildNodeWithName

swift,sprite-kit,nodes,fade,alpha
I want two different types of nodes to fade there alpha to 0 one after the other (with a sequence). However to find the nodes to fade, I'm using EnumerateChildNodeWithName and there is two of them, so I'm unable (I think) to use a sequence because I would have to...

SKAction repeatActionForever not spawning entity

objective-c,sprite-kit,performselector,spawning
Basically I have a spawn entity function that should in theory, spawn a random balloon onto the screen with certain properties. I have designed the method as such: -(void)spawnBalloon { int a = arc4random_uniform(self.frame.size.width); int b = self.frame.size.height - 50; CGPoint loc = CGPointMake(a, b); [self spawnBalloonAtPoint:loc]; } And this...

Issue comparing UIColors in Swift

ios,swift,sprite-kit,uicolor
I need to compare two UIColors, but for some reason it always return false. I tried to compare using == and .isEqual(), but neither of them seem to work. //This is a sample of the colors I have created let blue_color = UIColor(red: 122/255, green: 180/255, blue: 190/255, alpha: 1)...

Swift sprite kit activity indicator

ios,swift,sprite-kit
I am trying to add a simple, built in activity indicator to my sprite kit game as follows: let activityInd = UIActivityIndicatorView() activityInd.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2) self.scene!.view?.addSubview(activityInd) But it does not appear on the screen. Anyone knows a work around? ...

iPhone 5s SpriteKit drawing oddities

ios,sprite-kit,skscene,skview
I understand that the iPhone 5s has a pixel resolution of 640 x 1136 and a point resolution of 320 x 568 (for backward compatibility with non-Retina devices). The problem/confusion/oddity seems to come in when I'm working with SpriteKit. Example: I'm drawing a line from bottom-left corner (0, 0) to...

Swift - Adding background image behind a Sprite Kit Scene in View Controller

ios,swift,uiviewcontroller,sprite-kit
I am trying to add a background image in my view controller so my sprite kit game scenes can be in the foreground. It's important for me for my background image to stay on screen while the game scenes transition to each other. The problem I am having is how...

TextField does not work

swift,sprite-kit
I have a text field to type the word that, when (auto) and press the button (checkbutton) it should print out (correct). The problem is that it's not working. When I'm in office touchesBegan: if (TextField.text == "auto") lists me an error: Use Unresolved identifier "TextField". When this condition removed...

How do you tell if a node is on the screen spritekit swift

swift,sprite-kit
I am trying to figure out how to determine if a node is visible on the screen or off the screen. Is this just a true/false property of the node? Thanks. (Using swift spritekit)

Best way to convert SKShapeNode to SKSpriteNode [duplicate]

ios,swift,sprite-kit
This question already has an answer here: Changing the image of a SKSprite to an SKShapeNode 2 answers I'm creating a simple tetris game in swift to try out sprite kit/swift together. I'm creating tetris as practice using SKShapeNodes to create all the shapes and the game board. Unfortunately...

Having blur at the edges of the image in SpriteKit game

image,sprite-kit
I am almost done with my first SpriteKit game. One of the things that bothers me a lot is the quality of the images in my app. You can see below the difference between a label text and my logo's edges. The logo has clearly blurred at the edge points....

SpriteKit collision angle of line and circle is odd

ios,sprite-kit,skphysicsbody
Suppose a circle is enclosed in a diamond, and the circle heads due right. I would expect a series of continual 90 degree angles as the circle draws a square within the diamond. What I'm seeing, however, is that the circle eventually gets pushed toward the center of the diamond...

SpriteKit share button not workiing

ios,objective-c,sprite-kit,share
I am having a lot of difficulty with trying to make a share button which allows users to share my game on social media sites. I am developing a game using Sprite Kit. From what I have seen, I am under the impression that the actual code to initiate the...

How to call an object's methods in touchesBegan when touched?

objective-c,sprite-kit,touchesbegan
So in MyScene.m I create my Balloon objects and put it in the scene. for (int i = 0; i < 4; i++) { Balloon *balloonObject = [[Balloon alloc] init]; balloonObject.position = CGPointMake(50 + (75 * i), self.size.height*.5); [_balloonsArray addObject:balloonObject]; } while (_balloonsArray.count > 0) { [self addChild:[_balloonsArray objectAtIndex:0]]; [_balloonsArray...

Swift SpriteKit iOS - Collisions: didBeginContact for one sprite, and not for others

ios,swift,sprite-kit
I need to be able to run didBeginContact() for one sprite, but for the other, don't run it (but still collide with it). Here's what I have so far: enum ColliderType: UInt32 { case Player = 1 case Wall = 2 case ScreenBoundary = 3 } Screen Boundaries (I don't...

Best way to animate scaling and sizing of buttons in Swift?

ios,swift,sprite-kit
I'm using the code below to animate an intro-animation for buttons in an iOS Swift game. This code is inside of an update function and is the same for a lot of buttons. if self.creditsButton.size.width < 40 { self.creditsButton.size.width += 1 self.creditsButton.size.height += 1 } My question is; is there...

Centering the camera on a node in swift spritekit

swift,sprite-kit
I am creating a Terraria-style game in Swift. I want to have it so the player node is always in the center of the screen, and when you move right the blocks go left like in Terraria. I am currently trying to figure out how to keep the view centered...

How to make an SKNode continue in the same direction after finishing following a path

objective-c,sprite-kit
In my project I have an SKNode following a CGPathRef made with touchesMoved. What I want to have happen is once it reaches the end of the CGPathRef, it follows in the same direction that it ended in. I am using the SKAction followPath and tried to implement this by...

How to make a segue from SpriteKit GameScene to UIViewController programmatically in iOS 9 with Swift2

sprite-kit,segue,identifier,swift2,ios9
I need to make a segue from a GameScene to a UIViewController but i keep getting Use of unresolved identifier "push" although I did give it that identifier In the GameSceneViewController I added scene.viewController = self and in my GameScene I added var viewController: UIViewController? and func segue(){ self.viewController.performSegueWithIdentifier(push, sender:...

unwrapping SKPhysicsBody doesn't work

sprite-kit,skphysicsbody,forced-unwrapping
In my project, I create new nodes using a class called RocketMaker. Inside this class, I have a function called applyRecurringForce()... func applyRecurringForce() { var thrust: CGVector = CGVectorMake(100, 100) physicsBody!.applyForce(thrust) } My problem is I cannot access this function from the main scene. override func update(currentTime: NSTimeInterval) { /*...

How to access single sprite in array of sprites?

objective-c,sprite-kit,skspritenode
How do I access the first sprite in an array of sprites and change it's location to this? sprite.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height)); @property (nonatomic, strong) SKSpriteNode *aSprite; @property (nonatomic) NSMutableArray *sprites; one for the sprite one array to hold them...

SKAction runAction does not execute completion block

swift,sprite-kit
A SKSpriteNode is child of a SKNode and is placed on an array of SKSpriteNode for storage purposes. This SKSpriteNode is deleted using an animation. At the end of this animation a completion block is executed to perform some statements... The deletion must occurred both in the SKSpriteNode parent’s and...

Retain loop in a block

ios,objective-c,sprite-kit,objective-c-blocks,retain-cycle
I'm trying to get variables and properties in self in a block for actions to complete, but, if I reference self or a global variable in self when self is the object running the block, it warns me of a retain loop. Here's what I'm doing: I'm adding actions to...

show menu when paused a game ins spritekit

swift,sprite-kit
I created a game like as tower defence. I can successfully "pause" all game. And then i can resume the game with these code: let startLocation = CGPoint(x: location.x, y: location.y); let myNodeName = self.nodeAtPoint(location) if(myNodeName.Name == "Start"){ self.view!.paused = false } if(myNodeName.Name == "pause"){ self.view!.paused = true self.showPausedMenu() }...

SKAction runblock with arguments

ios,swift,sprite-kit
I have been trying to implement the following functionality in my game. I run an action on the sprite node (sprite node parent is nil) and the action should wait for my specified time and then add the node to self. I could not find any action which adds the...

How do I give the basket its exact shape, for a physics body, it is an image?

swift,sprite-kit,game-physics,skphysicsbody
basket.position = CGPointMake(self.size.width/2, self.size.height/8) basket.size.height = 50 basket.size.width = 75 basket.name = "basketNode" basket.physicsBody = SKPhysicsBody(rectangleOfSize: basket.size) basket.physicsBody?.usesPreciseCollisionDetection = true basket.physicsBody?.categoryBitMask = basketCategory basket.physicsBody?.dynamic = false self.addChild(basket) So currently, balls are falling from top of the screen, the players job is to catch them in the basket, for it to...

SpriteKit SKCropNode Masks everything

objective-c,ios8,sprite-kit,mask,skcropnode
I am trying to mask a node with SKCropNode class. I am doing it with my own init method in SKCropNode inherited class: - (id)init { self = [super init]; if (self) { self.maskNode = [[SKSpriteNode alloc] initWithColor:[SKColor blackColor] size:(CGSize){50,50}]; SKSpriteNode *contentNode = [[SKSpriteNode alloc] initWithImageNamed:@"Spaceship"]; [self addChild: contentNode]; self.userInteractionEnabled...

Sprite-Kit: SKAction.moveTo not working at all

ios,swift,sprite-kit,skaction
I'm facing a strange problem with Sprite-kit and Swift 1.2. I have the following code. The fingerSprite appears correctly in the middle of the screen. When I apply the moveTo action however, nothing happens. I'm quite new to Sprite-Kit and Swift so I might be doing something totally stupid but...

how to transition scenes with swift in spritekit

swift,sprite-kit
Having some trouble figuring out what i need to add to the below code in order to switch scenes when a node is touched. What do i need to replace the '....' with in order to have the code below it run. override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {...

Switching sprite positions with each other

ios,swift,sprite-kit
I have 6 sprites that I want to switch positions with each other every time a function is called. I also don't want any two (or more) sprites to ever be in the same position. I tried using this function but it didn't do anything. func newPositionPipe() { let pipePosition1...

IOS SpriteKit Colision Detection: Resetting Position of an Object

objective-c,sprite-kit,collision-detection
I'm working on Collision Detection where the hope is when Object1 moves down the screen and eventually hits Object2 it triggers the didBeginContact method and in turn, the resetPosition on Object1 which will bring Object1 back to the top of the screen. I've used NSLogs to test to make sure...

The protocol method of GKAgentDelegate is not right in Swift?

swift,sprite-kit,ios9,gameplay-kit
In GameplayKit, I want to conform the protocol GKAgentDelegate, hence use the delegate method func agentDidUpdate(agent: GKAgent). The problem is, in this method, the parameter agent is declared as GKAgent, not GKAgent2D, so that I cannot access agent.position, because the position property is in GKAgent2D, not GKAgent... However in Objective-C...

Better character movement according to touch location

objective-c,ios8,sprite-kit
I have a character spawned in the middle of a 3 by 3 platform (orthogonal & 2D sprite game). The platform is made up of 9 tiles. The character needs to move up if the touch is above him, left if touch is left of him and so forth. He...

Why is my rectangle being drawn wrong?

ios,swift,graphics,sprite-kit
I'm trying to draw a rectangle around my screen. Here's my code: let viewRect = SKShapeNode(rect: self.view!.frame) viewRect.strokeColor = SKColor.whiteColor() viewRect.lineWidth = 2.0 addChild(viewRect) I'm using self.view!.frame instead of self.frame because my scene is not the same size as my screen (the scene is stretched to fill my screen). I...

Can't move object in Sprite Kit

iphone,swift,sprite-kit
I am trying to make a bubble shooter kind of game but I cannot move my paddle. Any idea why this happens? // // GameScene.swift // gggame // // Created by divy on 6/17/15. // Copyright (c) 2015 divy. All rights reserved. // import SpriteKit class GameScene: SKScene , SKPhysicsContactDelegate...

Sprite Kit render performance using 16x16 tiles vs 32x32 tiles?

ios,objective-c,performance,sprite-kit,tiled
I've made a Tiled game. Right now I'm stress testing my phone's capabilities by increasing amount of nodes in the scene. There's physics based stuff, AI movement, Day & Night system, particles popping out here & there & plenty of other stuff going on under the hood for my scenes....

Swift iOS Sprite Kit - Fade sprite from one color to another [closed]

ios,swift,sprite-kit
I need to fade a sprite from one color to another over x duration. For example: A yellow sprite fades to pink sprite in 4 seconds. If possible, it needs to accept hex color codes, or something similar. Thanks! Toby....

Write a text in a circle in Sprite kit (swift)

swift,sprite-kit,skshapenode
i want draw a circle and put a text in it. what can i do? If i moved or resized the circle , text move or resize too var color = UIColor(red: 0x00, green: 0x44, blue: 0x44, alpha: 1) var Circle = SKShapeNode(circleOfRadius: 100 ) Circle.position = CGPointMake(frame.midX, frame.midY) Circle.strokeColor...

Swift error: “double is not convertible to UInt8”

ios,swift,sprite-kit
var dvalue:Double = 1.03 var stok1 = SKSpriteNode(imageNamed: "stok") stok1.zRotation = dvalue * stok1.zRotation This piece of code gives this error in the last line: "Double is not convertible to UInt8" How to fix this?...

SpriteKit - Detect if sprite still moving/stopped

ios,sprite-kit
I want to detect if my moving sprite (After applying an impulse) has stopped. Is there something like an event/function that handles this? Thanks...

Changing from NSUserDefaults to NSCoding

ios,swift,sprite-kit,nsuserdefaults,nscoding
I'm trying to create my first sprite kit swift game, and I have my game data working using nsuserdefaults. I want to make it more safe so I'm attempting to transition to NSCoding, but nothing I've found online has helped me completely and has just confused me (so sorry if...

Create linear motion with Swift in iOS [closed]

ios,swift,sprite-kit
What I'm trying to do seems very simple, yet I'm struggling to make it work. I'm creating a simple SpriteKit game, similar to FlappyBird. The main character stays vertically stationary while the user controls its horizontal motion. That part is no problem. At the same time, other game elements should...

Sprite Kit stop playing music file and start from the beginning

ios,objective-c,sprite-kit
Whenever I present my scene, I want to start playing a music file and stop the music playing from the last time my scene was presented. I'm trying to do it like this. [self removeActionForKey:@"Music"]; [self runAction:[SKAction repeatActionForever:[SKAction playSoundFileNamed:@"Music.wav" waitForCompletion:YES]] withKey:@"Music"]; Should I use AVAudioPlayer or [SKAction playSoundFileNamed:]? Also I...

Creating a boundary around a tiled map

ios,swift,sprite-kit
I've created a tiled map composed of multiple sprite nodes that are 367x367. I create this map like so: for var i = 0; i < Int(multiplier); i++ { for var j = 0; j < Int(multiplier); j++ { // Positive var map = SKSpriteNode(imageNamed: "tiledBackground.png") var x = CGFloat(i)...

Set SKTexture for SKSpriteNode with a given sprite.name

objective-c,sprite-kit
I've been trying to run the SKTexture change from a node on touch, said node is created with a loop: int nameIndex = 0; for (int i = 1; i <= 3; i++) { self.card = [SKSpriteNode spriteNodeWithImageNamed:@"front"]; NSString *nodeName = [NSString stringWithFormat:@"node%d", nameIndex]; self.card.name = nodeName; self.card.position = CGPointMake((((board-self.card.size.width)/3)*i),...

SpriteKit: Physics bodies breaking under too much force (applyForce)

ios,sprite-kit,skspritenode
I'm experiencing the oddest behaviour where the physicsengine has decided that walls (rectangular SKPhysicsBody) break if too many other objects (circular SKPhysicsBody) are pushing against it (using applyForce()) As far as I can tell SpriteKit has no notion of object breaking points or anything of the sort. Any ideas on...

Is it wise to export a Tiled layer into 1 big png file to save memory?

ios,objective-c,sprite-kit,tiled
I just made the background layer in Tiled for my map for Sprite Kit. The main layer is the background layer where the grass, dirt, water & the lot is drawn - this what the player character "walks on". This map is consisted of tiles that are 16x16 (keeping them...

How can i make the lose label to appear once the timer hits zero?

ios,swift,timer,sprite-kit
I'm a beginner in coding and I need help in the following code. I'm trying to make the "You Lose!" label appear after the timer hits zero, but when I try to do it; it doesn't show anything. Please help me! class Game: SKScene { let Ball = SKSpriteNode(imageNamed: "Red.png")...

Swift SpriteKit edgeLoopFromRect Issue

ios,swift,sprite-kit,cgrect,skphysicsbody
The following code recognizes the bottom and top edges of the scene and the ball bounces off as expected. However, the left and right edges of the scene are breached all the time. The ball goes off screen and then eventually returns back if enough force is applied. It is...

Orientation of screen?

ios,iphone,swift,sprite-kit
How do I make sure that the only orientations allowed are Portrait or Upside down portrait? I made the change in the project settings, but I'm having trouble making the change in my GameViewController. I need to make the change in this function: override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { if...

Stopping the countUp speed rate

swift,sprite-kit
I just started to learn Swift and Sprite Kit. I need assistance with the following code. I have a countUp that when the ball is touched the countUp starts but my problem is that every time I tap the ball the rate of speed in the countUp increases. I want...

Contact of Nodes with Subclass

ios,swift,sprite-kit
im creating a class to add my Meteors to the scene: import SpriteKit class Meteor: SKShapeNode { var meteorNode : SKShapeNode? var size : CGSize! //Acoes var acaoApagar = SKAction.removeFromParent() var acaoAndar : SKAction! //Numero Randomico var numRandom : Int = 0 var textoStringMeteor : String! //Colisoes let CollisionShoot :...

UIScrollView in sprite kit

ios,objective-c,iphone,uiscrollview,sprite-kit
I am new to programming and am developing an iOS game. I have used only one view controller, which initializes the home SKScene and isn't used at all after that, and have around 6 SKScenes that can navigate between each other with the following code (in their respective scenes) SKScene...

Spawn nodes at random times combing waitForDuration:withRange and runBlock: in an SKAction sequence

swift,sprite-kit,skspritenode,spawn,skaction
I am making a game with SpriteKit where I have nodes spawning at the top of the screen and falling. However, I want these nodes to spawn at a random time interval between 0.1 and 3 seconds. For example, the first node spawns in 1.3 seconds, the next in 1.8,...

passing info from collectionView to gameScene

uiviewcontroller,sprite-kit,uicollectionview
I have created a game using SpriteKit (GameScene and GameViewController) and Objective-C. Everything there works fine. Within the same App I have created a UIViewController and a second viewController in storyboard that uses CollectionView. I have the collectionView loading the array. I want to be able to tap on a...

Randomizing node movement duration

swift,sprite-kit,skspritenode,skaction
I am making a game in SpriteKit and I have a node that is moving back and forth across the screen and repeating using the code: let moveRight = SKAction.moveByX(frame.size.width/2.8, y: 0, duration: 1.5) let moveLeft = SKAction.moveByX(-frame.size.width/2.8, y: 0, duration: 1.5) let texRight = SKAction.setTexture(SKTexture(imageNamed: "Drake2")) let texLeft =...

Presenting a SKSpritenode from different class (“addChild”)

ios,sprite-kit
I have a Class for my Sprite and I'm trying to addChild from that class. The problem is it renders it and doesn't crash i just can't see the image. I know the images position is right because created and added the child from the gameScene class and it worked...

Delete child SKSpriteNode

objective-c,iphone,sprite-kit,skspritenode
Basically I am trying to make it so that when the user hits a fuel tank the old tank disappears and a new one is spawned in a random location. Right now it's detecting the collision but I can't get rid of the child. It will just add a new...

Swift 1.2 - Setting element in array of optional types to nil— not allowed when passed in?

ios,swift,null,sprite-kit
I have an array of boxes where the types are Box? to allow elements to be set to nil, if there is nothing there. I want the Box to set its spot to nil when it is removed from the scene. The following causes no complaints from Xcode: override func...

How to get a child sprite position in the view

swift,sprite-kit,skspritenode,sknode
I am attempting to get the child sprites position in the view based on the answer here and this for child in platformGroupNode.children { CGPoint p = [child.superview convertPoint:child.center toNode:self.view ] println(p) } However I am unsure how to use this with SKSpriteNode Children and SKNode Parents. I have also...

Can you apply delta time to an SKAction

swift,sprite-kit
I've started to notice in the game that I'm making that as the fps goes down as more nodes are on the screen, the nodes start to move with a little choppiness to them. I move the nodes with: let ran = Int(arc4random_uniform(1400)); let monster = SKSpriteNode(texture: text) monster.position =...

How to put quotes around a string that has quotes?

string,swift,sprite-kit,quotes
Making a game in spritekit and I have an array of famous historical quotations. I'm having trouble adding the quotes because the syntax requires me to use quotes. For example, I want to do something like ""apple"", ""orange"", but it won't let me use double quotations.

Program crashes when function called multiple times

ios,swift,sprite-kit,skspritenode
I have a function that moves a SKSpriteNode from one point to another. It works fine when I call it once. But when I call it multiple times, the whole program crashes. func play() { self.moveNode() self.moveNode() } func moveNode() { let player = SKSpriteNode(imagenamed: "player.png") player.position = CGPointMake(500.0, 500.0)...

CPU & Memory steadily increase & FPS drops all because of vector movement

ios,objective-c,sprite-kit
My CPU & Memory steadily increases over the course of roughly 6 minutes during play testing of my current Sprite Kit game. I've found that the method '-(void)walkToward:(CGPoint)targetPosition' inside the Player class is responsible (it moves the character to a tapped location on screen), but I DON'T understand why. The...

why isnt my second view loading after transition?

ios,swift,uiviewcontroller,sprite-kit
I have two views, the initial one that works fine, and a second one that I am trying to display after I transition to it from a button on the first view. However, when I click the button, the transition happens and the screen goes blank. Below is the viewDidLoad...

What does @“//” do in childWithName and when to use it

ios,nsstring,sprite-kit,sknode
I'm working on a SpriteKit project and my SKSpriteNode has a simple name: node.name = @"cat" However, when I try to do [self childWithName:@"cat"], I do not retrieve my object. Through some research I noticed some people mentioning I should be doing [self childWithName:@"//cat"] and that works. I was wondering...

Check if node is visible on the screen

ios,swift,sprite-kit
I currently have a large map that goes off the screen, because of this its coordinate system is very different from my other nodes. This has led me to a problem, because I'm needing to generate a random CGPoint within the bounds of this map, and then if that point...

Sprite Kit iOS Game development [closed]

ios,objective-c,image,animation,sprite-kit
I'm making a shooting game on iOS. I have got all my sprites working nicely now. The only thing I am wandering about is, how do you make an explosion effect? For example, lets say you have an image sprite, how can you make it so that the image sprite...

SpriteKit using 95-100% CPU when running game with large tilemap (JSTileMap)

ios,objective-c,swift,sprite-kit,jstilemap
My project runs at 55-60FPS on an iPhone 6 but anything older is completely unplayable because something is eating CPU. I think the issue is related to the number of tiles and layers on my map (64x256 with 4 layers) and Instruments shows "SKCRenderer:preprocessSpriteImp(..." taking 5198ms (23.2%) running time. Does...

Swift: Remove ads different scene in Spritekit

ios,swift,sprite-kit,mopub
I'm using the MoPub banner ad, I added the following code to my View Controller's viewDidLoad: self.adView.delegate = self self.adView.frame = CGRectMake(0, self.view.bounds.size.height - MOPUB_BANNER_SIZE.height, MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height) self.view.addSubview(self.adView) self.adView.loadAd() But it makes the ad visible in all the scenes when I only want it to be visible in the main...

need assistance in Collision between two objects

ios,swift,sprite-kit,collision-detection
Before hand, I'm a beginner iOS and coding in general. I'm using Sprite Kit and swift in the following code. Im having trouble understanding how SKPhysicsContactDelegate works. in the following code i have two objects "Ball" and "whiteBall" so what i want to do is every time "Ball" collides with...

How can I stop the timer?

ios,swift,timer,sprite-kit
I just started to learn how to program games for Apple and i've been searching how to stop a timer. In the following code i have i want to stop the timer i made but I'm having trouble how to stop it. i have no clue. Please help me! Thank...

SKShapeNode is appearing wrong dimensions

ios,swift,sprite-kit,skshapenode
I opened spritekit app sample and than added this code override func didMoveToView(view: SKView) { /* Setup your scene here */ var shapeNode = SKShapeNode(rect: view.frame) shapeNode.strokeColor = UIColor.redColor() shapeNode.lineWidth = 4; shapeNode.position = CGPoint(x: 0, y: 0) self.addChild(shapeNode) } which simply tries to add 4width border in the main...

SpriteKit remembering which sprite was touched

swift,sprite-kit,touch,swift2
I have a 'game' with 3 sprites. If a user clicks 'Sprite1', and thereafter 'Sprite2'. Is there some way to remember which sprites were pressed? Its only for 2 sprites if there are more i will need to empty the 'memory' and start over with the last one 'touched', i...