sprite-kit

How to scale/position nodes Swift SpriteKit? Custom View?

血红的双手。 提交于 2019-12-31 01:46:34
问题 I'm working on a game but can't figure out the right way to scale/ position everything. I have a universal app and when I switch from device to device the nodes aren't in the right place everytime. I'm using AspectFill because it sizes my nodes the the right way for each device. The problem is the positioning. I don't know if I'm right in making the conclusion that I need to figure out how to make the view the same size as the screen so that it changes for each device and then positions and

fatal error: use of unimplemented initializer 'init(size:)' for class

怎甘沉沦 提交于 2019-12-30 08:13:09
问题 I was testing my app on different devices and realized the sprite movements were quite inconsistent (running considerably faster on some devices as compared to others). I found this post and followed the instructions and removed the size parameters from all my SKScene s then I got the error: fatal error: use of unimplemented initializer 'init(size:)' for class 'SuperGame.PosterScene' Please see my PosterScene class below and the GameViewController class in which it is called. PosterScene

Spritekit crashes when entering background

橙三吉。 提交于 2019-12-30 08:10:12
问题 Allright guys, I've been developing an app in which I have a NSMutableDictionary with an SKAction object in it. The SKAction is for playing a sound. This all works well, except ... the app crashes upon entering background with the following stack trace: * thread #1: tid = 0x187d7, 0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10, queue = 'com.apple.spritekit.renderQueue, stop reason = EXC_BAD_ACCESS (code=1, address=0x1) frame #0: 0x3461b932 libGPUSupportMercury

SKTexture preloading

白昼怎懂夜的黑 提交于 2019-12-30 07:31:38
问题 When you preload textures using the spritekit preloadTextures function, it loads all the textures in the provided array into the memory at once. If you don't have the ability to split up your levels in your game with 'loading screens' but do have separate levels with different image files than each other, how can you keep from storing all the images in memory at once without sacrificing frame rate when spritekit loads the images when it needs to? 回答1: You could create a singleton class with

How to know which SKSpriteNode is affected by collision detection in Swift?

余生长醉 提交于 2019-12-30 06:49:54
问题 Situation: I have two or more ships on my iOS screen. Both have different attributes like name, size, hitpoints and score points. They are displayed as SKSpriteNodes and each one has added a physicsBody . At the moment those extra attributes are variables of an extended SKSpriteNode class. import SpriteKit class ship: SKSpriteNode { var hitpoints: Int = nil? var score: Int = nil? func createPhysicsBody(){ self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2) self.physicsBody?

What is SKSpinLockSync in Sprite Kit and how do I fix it

落爺英雄遲暮 提交于 2019-12-30 06:39:32
问题 I am receiving a bug report with the following stack trace and I have no idea what the problem is. I've seen suggestions that this could be caused by having an emitter's image in a texture atlas or by removing an emitter in the same run loop as it is added but I don't think either of these is happening. It's a sporadic issue and I can't recreate it. I only see it in bug reports. I would love any help. 0 libsystem_platform.dylib OSSpinLockLock + 1 1 SpriteKit SKSpinLockSync(int*, void ()()

Swift, SpriteKit: how to save the whole progress of a scene

為{幸葍}努か 提交于 2019-12-30 05:14:05
问题 I have build a swift game with a "GameViewController.swift" import UIKit import SpriteKit class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene(fileNamed:"GameScene") { // Configure the view. let skView = self.view as! SKView /* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFill skView.presentScene(scene) } } } and i have a scene called "GameScene"(it is the default game-file when you open swift and

SKCropNode masking edge anti-aliasing

你。 提交于 2019-12-30 04:06:10
问题 I created a circular mask and animate a sprite inside the mask by using sprite kit SKCropNode class. But the edge of the mask looks pixellated. Is there a way to use anti-aliasing to smooth the edges? 回答1: If you want to mask any SKNode/SKSpriteNode with an anti-aliasing effect - you can use SKEffectNode instead of SKCropNode. It works with animated nodes as well. Here is an example: // Set up your node SKNode *nodeToMask = [SKNode node]; // ... // Set up the mask node SKEffectNode *maskNode

How to reference the current Viewcontroller from a Sprite Kit Scene

纵然是瞬间 提交于 2019-12-30 03:21:25
问题 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? 回答1: 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

How can I make my level menu scrollable vertically?

这一生的挚爱 提交于 2019-12-29 09:57:22
问题 I have the following level Menu (as seen below). I would like to make it vertically scrollable, resulting in a total height double that of the screen (full scroll height). How can I achieve this? Below is the code for the image above: class LevelMenu: SKScene { let levelButtonSize = SKSpriteNode(imageNamed: "b1").size let levelButton1: SKSpriteNode = SKSpriteNode(imageNamed: "b1") let levelButton2: SKSpriteNode = SKSpriteNode(imageNamed: "b2") let levelButton3: SKSpriteNode = SKSpriteNode