skscene

Where is the right place to configure SKScene content in SpriteKit?

假如想象 提交于 2019-12-01 22:20:56
问题 Is it ok to configure (position sprites, add visible nodes etc) an SKScene's content in init method? Where is the right place for such things: init? didMoveToView? something else? 回答1: didMoveToView: is called every time the scene is presented by an SKView. Pros of positioning and adding sprites in didMoveToView: You can initialise many views without them grabbing a lot of memory. Cons: If you remove a view and then add it again didMoveToView: is called again. This means that you need to be

Significant fps drops when unpausing the view in Spritekit

早过忘川 提交于 2019-12-01 13:21:10
I've noticed significant fps drops (framerate drops between 5-10fps), when unpausing the view in SpriteKit. I tried this with empty project (Spritekit game template). Here is the code: if(!self.view.paused){ self.view.paused = YES; NSLog(@"Paused"); }else{ NSLog(@"Unpaused"); self.view.paused = NO; } If I pause the scene, everything works as expected and frames are steady at 60fps. I am testing this on device. if(!self.paused){ self.paused = YES; NSLog(@"Paused"); }else{ NSLog(@"Unpaused"); self.paused = NO; } This can make a problem with gameplay when unpausing because some frames will be

How to change SKscene size

眉间皱痕 提交于 2019-12-01 12:30:03
every time i run my app in my simulator the view scale always comes out to 768,1024 how do you change this to 1024,768. here is the default size code class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene(fileNamed:"GameScene") { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene.scaleMode =

AVAudioPlayer and performance issue in SpriteKit game

梦想与她 提交于 2019-12-01 12:29:08
I have problem with AVAudioPlayer and playing the short sounds in my spritekit game. I have quite dynamic game scene and when the user tap into particular element I want to play simple "beep" sound, but I notice that performing sound using AVAudioPlayer cause significant performance issue. My audio files are in .mp3 format. Also I have tried SKAction method (playSoundFileNamed) to perform sound and everything looks almost the same, I noticed the same performance issue. My question is what is the best practice to perform sound in SpriteKit. PS: I tried to find WWDC Adventure spritekit sample

Significant fps drops when unpausing the view in Spritekit

大憨熊 提交于 2019-12-01 10:33:50
问题 I've noticed significant fps drops (framerate drops between 5-10fps), when unpausing the view in SpriteKit. I tried this with empty project (Spritekit game template). Here is the code: if(!self.view.paused){ self.view.paused = YES; NSLog(@"Paused"); }else{ NSLog(@"Unpaused"); self.view.paused = NO; } If I pause the scene, everything works as expected and frames are steady at 60fps. I am testing this on device. if(!self.paused){ self.paused = YES; NSLog(@"Paused"); }else{ NSLog(@"Unpaused");

Memory leak when presenting SpriteKit scenes

空扰寡人 提交于 2019-12-01 02:19:53
I have an SKScene which is the overworld for my 2D game. It's like a neighborhood that the player can explore. The neighborhood is full of houses. Players can freely enter and exit houses. When the player enters a house, I call skView.presentScene(newHouse) to present the interior of the house as a new scene. When the player exits the house, I call skView.presentScene(overworld) to present the neighborhood again. The player is likely to enter & exit houses many times as they explore the neighborhood. Thus, the neighborhood scene and new instances of the house scene are presented many times.

SKScene Fails to deallocate memory resulting in bounded memory growth

半腔热情 提交于 2019-11-30 17:02:12
问题 I have been struggling with this for days, for some reason my SKScenes are not deallocating correctly, this results in bounded memory growth as each time i exit and enter a scene the memory jumps up. This means after say 10 rounds of the game the App crashes. As far as i'm aware after much checking i do not have any retain cycles or strong references to the scenes themselves and whilst i know textures are cached and held in memory surely once preloaded the memory shouldn't be going up each

How to reference the current Viewcontroller from a Sprite Kit Scene

故事扮演 提交于 2019-11-30 09:08:35
I'm having a hard time finding the answer to this question I assume is not that hard. How can I reference methods and properties defined on a viewcontroller from a SKScene ? And building on that: How can you reference the ViewController from a SKScene that was loaded from within another SKScene? A better option than my "back reference" answer is to use a protocol to explicitly define the methods that a SKScene subclass expects the UIViewController subclass to implement. Here are the steps you'll need to go through. 1) Define the protocol (contract) that the UIViewController will need to adopt

Strange EXC_BAD_ACCESS SpriteKit removeSubsprite crash

大城市里の小女人 提交于 2019-11-29 15:47:25
I am new to SpriteKit and just built my first game. Everything was working great until iOS 7.1. Now, after a few times of advancing to a new level and presenting a new Scene , it crashes. I don't think I am presenting it in an incorrect way: ZSSMyScene *nextLevel = [[ZSSMyScene alloc] initWithSize:self.size level:self.level score:score]; [self.view presentScene:nextLevel]; I get a EXC_BAD_ACCESS error, and it looks like it is happening on removeSubsprite , but I can't find anywhere in my code that I would be removing a subsprite: Not sure what other info to provide as this is just an obscure

Swift 3 (SpriteKit): Reseting the GameScene after the game ends

元气小坏坏 提交于 2019-11-29 02:34:46
I am wanting to 'reset' and 'restart' the GameScene so it is as if the GameScene was first called. I have looked at different methods for doing this, but each time I get a warning that I'm trying to add a node to a parent which already has a parent. However, in my code I delete all my existing nodes so I'm really confused as to how to reset the GameScene. This is how I do it now (this code is called when I want to restart the GameScene from scratch and it is called within the GameScene class): let scene = GameScene(size: self.size) scene.scaleMode = .aspectFill let animation = SKTransition