sprite-kit

SKAction waitForDuration() blocking SKAction sequence

拜拜、爱过 提交于 2019-12-24 18:32:48
问题 self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.waitForDuration(0.1), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ])) The last skaction does not get called. But when I remove the second waitForDuration, the last skaction gets called. self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.runBlock({ self.speed = realSpeed;

iAd didFailToReceiveAdWithError not working sometimes, displays white box

杀马特。学长 韩版系。学妹 提交于 2019-12-24 17:42:45
问题 I'm using Swift and SpriteKit, and everything is made inside my GameViewController and GameScene. This is all code concerning the ads inside my GameViewController: class GameViewController: UIViewController, ADBannerViewDelegate, GADBannerViewDelegate { var adBannerView: ADBannerView! var gadBannerView: GADBannerView! var bannerDisplayed = false var bannerNow = "iAd" override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene { //

Passing variables to SKScene

♀尐吖头ヾ 提交于 2019-12-24 17:17:50
问题 I'm trying to pass a preloaded array of SKTexture s from my SpriteKit scene's UIViewController when into the scene when it is initialised. However, I cannot seem to customise the initialisation method for SKScene to pass in an array. This is what I am trying to do: @interface MyViewController () @property (nonatomic, strong) NSArray *texturePack; @end <> - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; // Configure the view. SKView * skView = (SKView *)self.spriteView; if (

How Can I Save A Boolean In NSDefaults When A Button Is Pressed?

北战南征 提交于 2019-12-24 16:19:25
问题 I've coded a night and day button theme. If the user presses the day button, GlobalData.DayBool = true , and GlobalData.NightBool = false . When they press the night button, GlobalData.DayBool = false and GlobalData.NightBool = true . The background changes to night or white, depending on which one is true and false. Let's say that the user clicks the Night Button. GlobalData.NightBool = true , and GlobalData.DayBool = false , and the background changes to black. I want the booleans to be

Build a grid level for a game with SpriteKit and SWIFT

本秂侑毒 提交于 2019-12-24 16:13:06
问题 I’m searching the best way to build the levels for a game : The game will be composed with many levels, each levels will be unique. You’ll play an object (here the star), which is in movement on a grid. The object can move only to the bottom, it cannot go back. A level is composed with many cases, each cases will have a different behavior. My level will have a background, width of the screen, but the height will depend on the level, I suppose many times the height of the screen. The

Sprite Kit - Move scene and camera with sprite when sprite is going off screen

别来无恙 提交于 2019-12-24 15:14:04
问题 I am trying to make a scene that extends up off the screen for a certain distance, and I want the camera to stay centered on the player node. When the player reaches the top of the screen, I want the bottom nodes to disappear below the screen bounds and the new off screen part of the scene to become visible. Like Mario! I create the scene size like this: CGSize screenSize = CGSizeMake(skView.bounds.size.width, skView.bounds.size.height + (skView.bounds.size.height/3));//+ (skView.bounds.size

Swift: score increases twice because collision is detected twice?

你说的曾经没有我的故事 提交于 2019-12-24 15:09:51
问题 I'm building a sprite kit game in swift and I need the score to increase by 1 when collision between 2 nodes is detected. The score is stored in a variable named animalsCount and is outputted to a label node: //Score count in stats bar //Animal score count animalsCount = 0 animalsCountLabel.text = "\(animalsCount)" animalsCountLabel.fontSize = 45 animalsCountLabel.fontColor = SKColor.blackColor() animalsCountLabel.position = CGPoint (x: 630, y: 40) addChild(animalsCountLabel) The two sprite

How to detect when two objects touch in SpriteKit

被刻印的时光 ゝ 提交于 2019-12-24 15:00:38
问题 I have found nothing on the internet about how to do this. Im simply trying to run a line of code when to physics body touch. In this case I have an SKSpriteNode with a physics body and another for the ground. When they touch it should run the line of code this is all I have found so far. let catGroup:UInt32 = 0x1 << 0 let groundGroup:UInt32 = 0x2 << 1 cat.physicsBody?.categoryBitMask = catGroup cat.physicsBody?.contactTestBitMask = groundGroup ground.physicsBody?.categoryBitMask =

Swift + SpriteKit - Button is clickable even when not visible [duplicate]

余生颓废 提交于 2019-12-24 14:45:52
问题 This question already has answers here : SKLabelNode will disappear but is still clickable (2 answers) Closed 3 years ago . I seem to be having problems with one of the Nodes on my scene. I have a button: func createAttackButton() { attackButton.zPosition = 1 attackButton.anchorPoint = CGPointZero attackButton.position = CGPointMake(20, 20) attackButton.size = CGSize(width: 150, height: 40) addChild(attackButton) } This function is called when contact is made with the enemy. To run a function

Creating AppKit elements in a SpriteKit game

与世无争的帅哥 提交于 2019-12-24 14:43:17
问题 The title of the question really says it all. I am trying to tie in AppKit elements like buttons and other controls into a OS X SpriteKit game. My understanding is that AppKit elements can be placed on top of SKScenes, but how does this work? Would this be handled via an NSView? How does the layer get created in SpriteKit or is this a separate process altogether? 回答1: All AppKit UI elements are subclasses of NSResponder and most are subclasses of NSView This means like any other Cocoa app,