sprite-kit

Changing scenes with sprite kit after a certain time in Swift?

 ̄綄美尐妖づ 提交于 2019-12-08 13:48:11
问题 I would like to change from scene to scene after a certain amount of time on one scene in Swift. I am trying to create a survival type game that the player has to survive a level for so long before they can advance to the next level. I know that after I get to func being called I will be using this to go to the next scene. self.view?.presentScene(GameScene2()) I am sure that something along the lines of NSTimer is going to be used, but anything that can be given to point me in the right

When projectile hits two “monsters” the didBeginContact method crashes. I know why but i don't know how to avoid it

◇◆丶佛笑我妖孽 提交于 2019-12-08 13:43:00
问题 So I have this code from the tutorial: func didBeginContact(contact: SKPhysicsContact) { // 1 var firstBody: SKPhysicsBody? var secondBody: SKPhysicsBody? var body: SKPhysicsBody //contact.bodyB.node!.physicsBody!.allContactedBodies().count if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask { firstBody = contact.bodyA secondBody = contact.bodyB println("1 = A, 2 = B") } else { firstBody = contact.bodyB secondBody = contact.bodyA println("2 = A, 1 = B") } // 2 if ((firstBody!

setting SKScene delegate from viewcontroller, delegate not found

扶醉桌前 提交于 2019-12-08 13:37:15
问题 Trying to open a view controller from an SKScene. Found https://stackoverflow.com/a/20072795/1686319 very helpful, but i get an error when trying to set the delegate from the view controller. No visible @interface for 'SKScene' declares the selector 'setDelegate:' EABMyScene.h #import <SpriteKit/SpriteKit.h> @protocol EABMySceneDelegate <NSObject> -(void)doSomething; @end @interface EABMyScene : SKScene { } @property (nonatomic, weak) id <EABMySceneDelegate> delegate; @end Any idea? Update:

Does adding new action for the scene remove automatically the one before in SpriteKit?

本小妞迷上赌 提交于 2019-12-08 13:14:31
I want to know if I made a sequence action and while this sequence is running a new action added to the scene , Does the new action stop the sequence ? If yes , how i can make both of them working if the new action is added in swift ? The only time a new action will interfere with any running actions is if both actions share the same key. If you do not assign a key, then every time you add an action, it gets added to the action pool and will run concurrently. If you just give it a try, I'm sure you'll find the answer yourself. But anyway, I tried it for you: node.run(SKAction.sequence(

Hit fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

断了今生、忘了曾经 提交于 2019-12-08 13:13:17
问题 I programming a simple game and at the first collision I get the following error: Hit fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) Here's my code: func didBeginContact(contact: SKPhysicsContact) { var firstBody: SKPhysicsBody var secondBody: SKPhysicsBody if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask { firstBody = contact.bodyA secondBody = contact.bodyB } else { firstBody = contact.bodyB secondBody = contact.bodyA } if ((firstBody

Turn off touch for whole screen, SpriteKit, how?

故事扮演 提交于 2019-12-08 13:09:10
问题 I'm trying to temporarily disable touch on the entire screen, despite their being many sprites with touchesBegun onscreen. I thought, obviously wrongly, turning off touch for the scene would do it: scene?.isUserInteractionEnabled = false But that didn't work, so I tried this, which also didn't work: view?.scene?.isUserInteractionEnabled = false That also didn't work, so I tried this, also from inside the scene: self.isUserInteractionEnabled = false 回答1: There is no global method to turn off

How To Create Array Of SKSpriteNodes? (swift, spritekit)

泄露秘密 提交于 2019-12-08 12:37:44
问题 I have 12 ball sprites all of which have the same attributes. Is it possible to put them all in an array so I dont have to keep typing.... ball1.size....... ball2.size........ ball3.size...... Etc. I would like to create an array called allBalls and then just change every ball through one line of code like shown... allBalls.size..... 回答1: To create an array of SKSpriteNode s you could do the following: let allBalls = [ball1, ball2, ball3] // Of type Array<SKSpriteNode> Then iterate through

how to add SKSpriteNode in a loop [closed]

被刻印的时光 ゝ 提交于 2019-12-08 11:37:43
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I want to add some squares in a scene by loop. But this code has a problem. What is wrong? var shape = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 100, height: 100)) for (var i=0 ; i<10 ; i++) { shape.name = "shape\(i)" shape.position = CGPointMake(20,20) self.addChild(shape) } 回答1: You have a

How can I place a SpriteKit AdBanner at the Top of the View?

只谈情不闲聊 提交于 2019-12-08 11:34:57
问题 How can i place an iAd Banner at the Top of the View in a SpriteKit Application? The Banner is working perfectly but on the wrong position. Here is the code for the iAd Banner , but the its always below: ViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Configure the view. SKView * skView = (SKView *)self.originalContentView; skView.showsFPS = YES; skView.showsNodeCount = YES; // Create and configure the scene. SKScene * scene = [MyScene sceneWithSize:skView.bounds.size]; scene

Adding physics body to Sprite in SpriteKit alters its position fractionally

白昼怎懂夜的黑 提交于 2019-12-08 11:06:55
问题 I have a Swift / SpriteKit game in which a whole bunch of sprites have physics bodies to detect collision with the player - but otherwise they are not supposed to move. My issue is that as soon as I add a physics body, the sprite appears to move fractionally. More specifically its position changes by a small fraction (like 0.0003). Initially such a small change does not matter, but it keeps changing like this until the sprite actually moves onscreen and messes up the game. To narrow it down I