sprite-kit

SKSpriteNode gets hidden below parent node

≡放荡痞女 提交于 2019-12-07 03:07:48
问题 Using Swift and SpriteKit, I have a problem with SKSpriteNode not showing when being added as a child to another SKSpriteNode. In contrast, a SKLabelNode put in exactly the same place does show up. // does not show up, expected a white square override func renderBody(parentNode: SKNode, position: CGPoint) { let node = SKSpriteNode(color: UIColor.whiteColor(), size: CGSize(width: 48, height: 48)) node.position = position parentNode.addChild(node) } // does show up as white text in the correct

How to properly calculate 1 second with deltaTime in Swift

…衆ロ難τιáo~ 提交于 2019-12-07 03:03:11
问题 I'm trying to calculate an elapsed second in deltaTime but I'm not sure how to do it, because my deltaTime constantly prints 0.0166 or 0.0167. Here is my code: override func update(_ currentTime: CFTimeInterval) { /* Called before each frame is rendered */ deltaTime = currentTime - lastTime lastTime = currentTime How do I make it so I can squeeze some logic in here to run every second? EDIT: I was able to come up with the following, but is there a better way? deltaTimeTemp += deltaTime if

Gradually change background color in Swift

时光毁灭记忆、已成空白 提交于 2019-12-07 02:40:13
问题 I'm making a game where I need the background color to change slowly. As the user plays the level, the background color should be changing to show progress. I was thinking of having the starting color be light blue, and then changing to green, then yellow, then orange or something like that over time. Any ideas? 回答1: Here's a working example, just change the colors: var backgroundColours = [UIColor()] var backgroundLoop = 0 override func viewDidLoad() { super.viewDidLoad() backgroundColours =

Does a project have to be created as a sprite kit or can the framework simply be added?

早过忘川 提交于 2019-12-07 02:05:32
问题 I am taking a step backwards to learn sprite kit for the 2D Games I'm making, as opposed to using UIKit. In all the tutorials I've gone through, they've created the new project as a Sprite-Kit as opposed to single-view. Just wondering if I'll have to recreate my games or if I can simply add the sprite kit framework to my existing project? Thanks. 回答1: The framework can simply be added. Check the Sprite Kit Programming Guide from Apple. Apple is creating their Sprite Kit's example from a

Whats the correct way, using “init” or “didmove”?

穿精又带淫゛_ 提交于 2019-12-07 01:44:53
问题 Language: Swift 3.0 --- IDE : Xcode 8.0 beta 2 --- Project : iOS Game (SpriteKit) I create a game for iOS and i know Apple is really strict with their rules to accept the app/game. So i want to know which is the correct way to setup a game. I learned from google to create a new SpriteKit Project and do the following setup : In GameViewController.swift clear viewDidLoad() and add all this : override func viewDidLoad() { super.viewDidLoad() let skView = self.view as! SKView let scene =

Strange Exception with GameCenter

若如初见. 提交于 2019-12-07 01:34:13
问题 I keep getting this crash report from GA and users... However i cannot reproduce this exception by testing iphone5,5s,6 with both ios7 and ios8. This issue comes nowhere when application did enter to background. The strange part is that gamecenter will call spritekit, for showing achievement banner? Does anyone has the same issue? Last Exception Backtrace: 0 CoreFoundation 0x23c99e3f __exceptionPreprocess + 127 1 libobjc.A.dylib 0x31371c8b objc_exception_throw + 38 2 CoreFoundation 0x23c9f189

zPosition of SKNode relative to its parent?

浪尽此生 提交于 2019-12-07 01:26:34
问题 I always thought that the the zPosition of a SKNode would be relative to its parent, but right now I'm experiencing the opposite effect. I have two parent SKNodes in my scene, which have a zPosition of 1 (node1) and 2 (node2). What I want to achieve is that node2 should ALWAYS be layered ABOVE node1. But unfortunately, the child nodes of node1 (which have a zPosition of 1-50) are all layered above the child nodes of node2 (which currently have no zPosition). Is there any way to solve this

Create Button in SpriteKit: Swift

心已入冬 提交于 2019-12-07 00:37:04
问题 I want to create a button in SpriteKit or in an SKScene that sends the view to another view controller. I tried using the "performSegue with identifier ", however apparently an SKScene doesn't support this. How would I create a button that sends the view to another view with SpriteKit ? This is the code that I've tried using to perform this action. The line with "HomeButton.prepareForSegueWithIdentifier()" is just an example. It won't actually let me add the "prepareForSegue" part, it doesn't

Memory Leak for .showsPhysics

五迷三道 提交于 2019-12-07 00:00:08
问题 I have just recently spent the past 5 hours trying to debug a memory leak in my Spritekit App. After app Launch, I noticed a small climb in my memory usage. I spent 3 of those 5 hours digging through reference material, learning about strong VS Weak with ARC (Definitely Recommend Reading up on that for Intermediates Such as myself) Is anyone else experiencing this issue? If so is there any sort of explanation? Here is a small snippet of my GameViewController: class GameViewController:

ARKit / SpriteKit - set pixelBufferAttributes to SKVideoNode or make transparent pixels in video (chroma-key effect) another way

你离开我真会死。 提交于 2019-12-06 23:01:25
问题 My goal is to present 2D animated characters in the real environment using ARKit . The animated characters are part of a video at presented in the following snapshot from the video: Displaying the video itself was achieved with no problem at all using the code: func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? { guard let urlString = Bundle.main.path(forResource: "resourceName", ofType: "mp4") else { return nil } let url = URL(fileURLWithPath: urlString) let asset = AVAsset(url