sprite-kit

Handling Multiple GestureRecognizers

帅比萌擦擦* 提交于 2019-12-12 08:44:47
问题 I've run into an issue understanding UIGestureRecognizers . My goal right now is to have a set of GestureRecognizers to do different tasks, for example: override func viewDidLoad() { mainScene = GameScene(size: self.view.bounds.size) main = view as! SKView mainScene.panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(shiftView(recognizer:))) main.addGestureRecognizer(mainScene.panRecognizer) mainScene.tapRecognizer = UITapGestureRecognizer(target: self, action: #selector

Swift: Unable to downcast AnyObject to SKPhysicsBody

断了今生、忘了曾经 提交于 2019-12-12 08:43:02
问题 Apple has the following method in the SKPhysicsBody class. /* Returns an array of all SKPhysicsBodies currently in contact with this one */ func allContactedBodies() -> [AnyObject]! I noticed it returns an array of AnyObject. So I read about how to deal with down casting AnyObject Here I want to loop through the allContactedBodies array of my physics body. The problem is, no matter what I try I just can't get things to work. I tried this first: for body in self.physicsBody.allContactedBodies(

How can I replace level button image with a screenshot of the level game scene?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 08:41:41
问题 I know how to take and save a screenshot to the photo library. I do this using the code below. I would like to replace my level scene button images with screenshots of my gameScene. Say my image buttons are 150x150. How can I achieve this? func takeScreenShot(scene:SKScene) { let bounds = self.scene!.view?.bounds UIGraphicsBeginImageContextWithOptions(/*CGRect(x: 0, y: 0, width: 100, height: 100).size*/bounds!.size, true, UIScreen.main.scale) self.scene?.view?.drawHierarchy(in: bounds!,

SKShader to create parallax background

有些话、适合烂在心里 提交于 2019-12-12 08:13:44
问题 A parallax background with a fixed camera is easy to do, but since i'm making a topdown view 2D space exploration game, I figured that having a single SKSpriteNode filling the screen and being a child of my SKCameraNode and using a SKShader to draw a parallax starfield would be easier. I went on shadertoy and found this simple looking shader. I adapted it successfully on shadertoy to accept a vec2() for the velocity of the movement that I want to pass as an SKAttribute so it can follow the

ObjectAL automatic interruption handling error

a 夏天 提交于 2019-12-12 07:52:58
问题 I've been playing with phone calls while (SpriteKit)game running in order to test interruptions. I am using example from ObjectAL documentation called : "Using the OpenAL Objects and OALAudioTrack". So, I let the library to handle this automatically... [OALAudioSession sharedInstance ]. handleInterruptions = YES And it works but partially. For example, with simple setup with 3 sounds I get next error message : OALAudioSession activateAudioSession]: Could not activate audio session after 2

How to bring a SKSpriteNode to front?

怎甘沉沦 提交于 2019-12-12 07:24:34
问题 How can I bring a SKSpriteNode to the front of all other node? With UIView, I can use bringSubviewToFront to bring an uiview in front of other views. 回答1: You can't "bring it to front" but you can change the zPosition of it. The higher the zPosition of the node the later it gets rendered. So if you have three nodes with zPositions of -1, 0 and 1 then the -1 will appear at the back. Then the 0. Then 1 will appear at the front. If they all use the default zPosition of 0.0 then they are rendered

How to instantiate SKSpriteNode spritekit swift 3

瘦欲@ 提交于 2019-12-12 06:59:33
问题 I have a 2 player space shooter game and am having trouble with the shooting part. I currently have a ship that moves it's x position with your finger. I want it to shoot strait up when the user pushes the "fire" button. So here is my question. How can I instantiate my bullet(SKSpriteNode) at the gun tip and shoot upwards when the user pushes the "fire"? 回答1: This is pretty basic but you need to: Create a new sprite for the bullet Position the bullet in the same place as the ship Make the

SpriteKit texture not visible

本秂侑毒 提交于 2019-12-12 06:38:07
问题 I'm developing a game where there are characters with a number of animations, which play when the user uses the game controls for moving, fighting, etc. There is a normal state, i.e. when the user is not touching any control, the player's character's texture has been assigned to a Normal State or Resting State texture. If the user exercises these controls very quickly, then the player's character's texture disappears when he goes back to the Normal state. If any of the controls are used

Changing scene causes zoom

大兔子大兔子 提交于 2019-12-12 06:14:42
问题 When going from GameScene to PlayScene using this code below, all works fine: for touch: AnyObject in touches { let location = touch.locationInNode(self) if self.nodeAtPoint(location) == self.playButton1 { var scene = PlayScene(size: self.size) let skView = self.view as SKView! skView.ignoresSiblingOrder = true scene.scaleMode = .ResizeFill scene.size = skView.bounds.size skView.presentScene(scene) } } But when i am going from PlayScene to GameScene using this code below, it gets zoomed in:

Cannot assign value of type '[SKNode]' to type 'SKSpriteNode!'

二次信任 提交于 2019-12-12 05:28:23
问题 I'm writing a Galaga-style game in Swift 3 with SpriteKit and I keep getting an error that says Cannot assign value of type '[SKNode]' to type 'SKSpriteNode!' Can anyone explain what this means so that I can fix it myself in the future and also give me a possible solution? Here's the function where I get the error: override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = (touch as UITouch).location(in: self) if fireButton = self.nodes