sprite-kit

Confusion about coordinates, frames & child nodes in SpriteKit on iOS?

╄→尐↘猪︶ㄣ 提交于 2020-01-02 02:42:07
问题 I'm still playing around with learning SpriteKit in iOS & have been doing lots of reading & lots of experimenting. I'm confused by something else I've found* regarding coordinates, frames & child nodes. Consider this snippet of code, in which I'm trying to draw a green box around my spaceship sprite for debugging purposes: func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // VERSION 1 spaceship.position = CGPointMake

Swift : How to handle a lot of textures in memory

*爱你&永不变心* 提交于 2020-01-01 16:48:10
问题 I have a lot of characters in my game and because of that I have so many textures. When a texture atlas is loaded (containing about 5 different image textures) it increases the memory use and keeps it there at that amount. So the more textures just keeps driving that number up and up until sometimes the application crashes. I don't need all the characters at once, how can i maybe load some character textures when I need them and deallocate the others when i don't, but ill need to be able to

Purposely slowing down FPS Spritekit

元气小坏坏 提交于 2020-01-01 16:37:14
问题 Is it possible to purposely slow down the SpriteKit scene's FPS? I was thinking if this is possible to make debugging of my game easier. 回答1: You can do something like this as well (as an addition to crashoverride777's answer) by slowing down nodes or physics: To make nodes going into slow-mo (you can do this per node): self.speed = 0.2 //where self is a scene or to do the same with physics: self.physicsWorld.speed = 0.2 //where self is a scene 回答2: You can change the FPS value of your SKView

How to get all actions name on Xcode action editor in sks file “SpriteKit action”

流过昼夜 提交于 2020-01-01 15:38:33
问题 I've a SpriteKit action file with some actions inside. To use one action, I use: let action = SKAction(named: "Shake") Instead is possible to use directly the name inside MyActions.sks file? Something like: let actions = SKScene(fileNamed: "MyActions.sks")` let shakeAction = actions.listOfAction.Shake //this is my guess If I print the scene file: let actions = SKScene(fileNamed: "MyActions.sks") print(actions) the output is: Optional({ "_info" = { "_previewScenePath" = "PippiPompiere

How to get all actions name on Xcode action editor in sks file “SpriteKit action”

独自空忆成欢 提交于 2020-01-01 15:37:14
问题 I've a SpriteKit action file with some actions inside. To use one action, I use: let action = SKAction(named: "Shake") Instead is possible to use directly the name inside MyActions.sks file? Something like: let actions = SKScene(fileNamed: "MyActions.sks")` let shakeAction = actions.listOfAction.Shake //this is my guess If I print the scene file: let actions = SKScene(fileNamed: "MyActions.sks") print(actions) the output is: Optional({ "_info" = { "_previewScenePath" = "PippiPompiere

Metal SCNProgram - can't render a SpriteKit scene that has video content

不问归期 提交于 2020-01-01 12:08:10
问题 I'm (desperately) trying to use a video as texture in a SCNScene with some fancy shader modifiers. I'd like to use a SCNProgram for that part. I've just taken the one from here: #include <metal_stdlib> using namespace metal; #include <SceneKit/scn_metal> struct MyNodeBuffer { float4x4 modelTransform; float4x4 modelViewTransform; float4x4 normalTransform; float4x4 modelViewProjectionTransform; }; typedef struct { float3 position [[ attribute(SCNVertexSemanticPosition) ]]; float2 texCoords [[

How to create another screen on my app

半腔热情 提交于 2020-01-01 11:34:49
问题 So I was wondering, with the default "game" Xcode configuration. How would you make another SKScene? Like lets say I wanted to have a menu or something? Basically how would I create another document titled "title.swift" and then programmatically be able to switch back and forth through them? That way I could go from a menu to the game scene without muddling up my code? I cant find where in the remade code code it actually tell swift to display the game scene that was premade with the "game"

How to progressively blur a SKSpriteNode's image using Sprite Kit?

谁说我不能喝 提交于 2020-01-01 09:28:11
问题 Can someone provide an example of how to progressively blur a SKSpriteNode's image using Apple's Sprite Kit? For instance, let's say the user touches a button on the screen which will then trigger the background to slowly (i.e. progressively) blur until it reaches a specific threshold. Ideally, I would like to reverse the process too (e.g. allow the user to unblur the image by touching the same button). 回答1: There are two possible paths to take on this, both use SKEffectNodes SKEffectNodes

Stopping an running SKAction - Sprite Kit

百般思念 提交于 2020-01-01 08:36:09
问题 The following code will animate a rotation. let something:SKSpriteNode = SKSpriteNode() func start(){ let rotateAction = SKAction.rotateToAngle(CGFloat(M_PI), duration: 10.0) something.runAction(SKAction.sequence([rotateAction])) } Now I want to stop the animation within the animating duration. Is there anything similar to the following? I want to stop the animation when the user touches the screen. func stop(){ something.SKAction.stop() } 回答1: You just have to use either: something.paused =

SKAudioNode() crashes when plugging in/out headphones

时光毁灭记忆、已成空白 提交于 2020-01-01 08:34:06
问题 I am using a SKAudioNode() to play background music in my game. I have a play/pause function and everything is working fine until I plug in my headphones. There is no sound at all and when I call the pause/play function I get this error AVAudioPlayerNode.mm:333: Start: required condition is false: _engine->IsRunning() com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning() Does anyone knows what this means? Code: import SpriteKit class GameScene: SKScene {