sprite-kit

Pausing game during call, Difference between getting a call and pressing home button?

老子叫甜甜 提交于 2019-12-10 10:51:30
问题 My game pauses ok when home button is pressed. But it doesn't when I get a call. Its actions are resumed when the game becomes active. I don't get the difference between getting a call and pressing HB. Please help me out. Thanks. func pauseGame(){ initResumeButton() pause.removeFromParent() gamePaused = true self.paused = true } func resumeGame(){ resume.removeFromParent() initPauseButton() gamePaused = false self.paused = false } func registerAppTransitionObservers(){ NSNotificationCenter

Pausing a SpriteKit Game - UIApplicationWillResignActive vs. UIApplicationDidBecomeActive?

荒凉一梦 提交于 2019-12-10 10:46:51
问题 I understand the differences between the two methods but I was wondering if there were disadvantages to using UIApplicationWillResignActive as opposed to UIApplicationDidBecomeActive (or, UIApplicationDidEnterBackground) when doing something such as pause a SpriteKit game. I've been roaming past threads on the site and have noticed that generally in response to questions asking how to pause a SpriteKit game, UIApplicationDidBecomeActive and UIApplicationDidEnterBackground are suggested as

Presenting a UIViewController from an SKscene (SpriteKit)

孤街醉人 提交于 2019-12-10 10:38:53
问题 There are several posts on the internet asking how to correctly combine SpriteKit and Storyboard/Interface builder. In particular nobody is able to move from an SKscene to a desired UIViewController. NONE of the solutions on the net really address this problem! Is it really not possible to do this?? If so, it would be a significant limitation of SpriteKit... 回答1: You cannot move directly from an SKScene to another UIViewController . However, the SKScene is already contained in a

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

只愿长相守 提交于 2019-12-10 10:29:28
问题 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, then 2.5, then 0.8, and so forth forever. I'm not sure how to utilize the waitForDuration function to do this. The code that I currently have is: let wait = SKAction.waitForDuration(3, withRange: 2) let spawn = SKAction.runBlock { addTears

Swift convenience initializer extension for SKPhysicsBody

泄露秘密 提交于 2019-12-10 10:13:30
问题 extension SKPhysicsBody { /// anchorPoint version of init(rectangleOfSize:center:) convenience init(rectangleOfSize s: CGSize, withAnchorPoint anchorPoint: CGPoint) { var center = CGPoint() center.x = (s.width / 2) - ( s.width * anchorPoint.x) center.y = (s.height / 2 ) - ( s.height * anchorPoint.y) self.init(rectangleOfSize: s, center: center) } } I got this error on runtime -[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0 ***

Increase jump height on longer touch until maximum height

一笑奈何 提交于 2019-12-10 10:06:20
问题 I'm using the following methods to make my character jump: override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { if onGround && !gameOver { self.character.physicsBody?.applyImpulse(CGVectorMake(0, 75)) self.onGround = false } } override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { } This works fine, but I want to make the character jump a certain height based on the length of the touch until a maximum. I've tried something with frame durations

SKAction: How to Animate Random Repeated Actions

五迷三道 提交于 2019-12-10 09:51:28
问题 I'd like to run a repeating SKAction but with random values on each repeat. I have read this question here that shows one way to do this. However, I want my sprite's movements to be animated, not simply changing its position. One solution I have come up with is to run a sequence of actions, with the final action calling my move method in a recursive fashion: - (void)moveTheBomber { __weak typeof(self) weakSelf = self; float randomX = // determine new "randomX" position SKAction *moveAction =

Passing dynamic Int variable from one class to another class in Swift

青春壹個敷衍的年華 提交于 2019-12-10 09:44:02
问题 Am new to swift 2 and i got stuck in passing a variable from one class to another. I have a class "GameScene" in it I have a public variable score and it keeps updating in update function. I want to send the score value at the time when two nodes collide with each other. Once it collides I go to another scene using "mainview .presentScene( gameoverScene )" syntax. I want the updated score in gameoverscene. I tried using " private let _gameScene = GameScene() " in gameoverscene and passing it

What is the method unarchiveFromFile in GameViewController for?

半城伤御伤魂 提交于 2019-12-10 09:29:53
问题 When I tried to add different scenes to my game in Swift, I encountered the method unarchiveFromFile. The problem with this method is that it only works with the GameScene class. If you call it from extension SKNode { class func unarchiveFromFile(file : NSString) -> SKNode? { if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") { var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil) var archiver = NSKeyedUnarchiver

Swift SpriteKit SKSpriteNode's “Sometimes” Don't Show Up

廉价感情. 提交于 2019-12-10 08:17:56
问题 I am making an iOS using Swift and SpriteKit. However I am experiencing irregularity in the running of my app. Sometimes the ship SKSpriteNodes doesn't appear on the screen, sometimes the bullet's SKSpriteNodes don't appear, sometimes everything shows up fine (I add the bullets elsewhere in the code). In all cases I am not making changes to the code between runs. I am starting the app on this screen directly so I'm thinking maybe it has something to do with these SKSpriteNodes not having