skscene

Moving Camera in SpriteKit Swift

蹲街弑〆低调 提交于 2021-02-07 03:06:12
问题 I am creating a game in sprite kit using swift, and I am trying to be able to move the SKScene around with a finger because not all of the nodes fit within the scene. I have already created world, overlay, and camera nodes with this code. override func didMoveToView(view: SKView) { world = self.childNodeWithName("world")! if !isCreated { isCreated = true // Camera setup self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.world = SKNode() self.world.name = "world" addChild(self.world) self.cam =

Moving Camera in SpriteKit Swift

你。 提交于 2021-02-07 03:03:16
问题 I am creating a game in sprite kit using swift, and I am trying to be able to move the SKScene around with a finger because not all of the nodes fit within the scene. I have already created world, overlay, and camera nodes with this code. override func didMoveToView(view: SKView) { world = self.childNodeWithName("world")! if !isCreated { isCreated = true // Camera setup self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.world = SKNode() self.world.name = "world" addChild(self.world) self.cam =

create SKScene subclasses programmatically, without size info?

落花浮王杯 提交于 2020-06-22 12:05:22
问题 I'm trying to learn how to make a GameManager type class, and making individual classes for each of my GameScenes... probably the wrong thing to do, but for the sake of this question, please accept this as the way to do things. My GameManager looks like this, having a reference to each of the scenes, that's static: import SpriteKit class GM { static let scene2 = SecondScene() static let scene3 = ThirdScene() static let home = SKScene(fileNamed: "GameScene") } How do I create a SKScene

Get a list of all SpriteKit Scenes in App Bundle

浪子不回头ぞ 提交于 2020-01-16 19:24:48
问题 As a followup to this question, I need to iterate over each .sks file in a folder, namely, "Levels". My project looks like this: Here's what I've written: let directory = NSFileManager.defaultManager().currentDirectoryPath let paths = NSBundle.mainBundle().pathsForResourcesOfType("sks", inDirectory: directory) let files = paths.map() { (path : AnyObject) -> String in return (path as String).lastPathComponent } println("Files\n\(files)") let firstLevel = files[0] if let scene = SKScene

How do I size sprites in a universal sprite kit game

泪湿孤枕 提交于 2020-01-14 05:16:08
问题 I'm relatively new to swift programming. I have made an app where I didn't use SpriteKit and I would size most views by scaling down the images to a multiple of the screens width and height. Not sure if this is the best tactic, but it worked and I was able to build an app that looked good on all devices. With spritekit and the scene.sks files, I don't have the option of auto-layouts to size my sprites like I did before. There isn't a lot of content about universal apps online, so I'm

Change SKScene using presentScene()

烈酒焚心 提交于 2020-01-14 02:48:09
问题 In my SpriteKit Game i'm using: self.scene!.removeFromParent() let skView = self.view! as SKView skView.ignoresSiblingOrder = true var scene: PlayScene! scene = PlayScene(size: skView.bounds.size) scene.scaleMode = .AspectFill skView.presentScene(scene, transition: SKTransition.fadeWithColor(SKColor(red: 25.0/255.0, green: 55.0/255.0, blue: 12.0/255.0, alpha: 1), duration: 1.0)) to move from one scene to another. But how can I go back to the original scene? Using the same principle of code

How to determine if an ScnNode is left or right of the view direction of a camera node in SceneKit

我只是一个虾纸丫 提交于 2020-01-13 12:56:13
问题 I have a camera in the center of SceneKit scene at position(0,0,0) I'm rotation the camera around the y-axis to show different parts of the scene. I want to show arrows at the left/right side of my screen to show in which direction the user has to move to view a target object. How can I calculate if a ScnNode is positioned at the left of right side of my view direction? I know: position and rotation of the camera node position of the target node 回答1: Calculate the vector to the node relative

AvAudioPlayer not working?

Deadly 提交于 2020-01-07 01:22:37
问题 I create the AVAudioPlayer object and play the music within the scene, if i transition through to another scene and then go back to the original scene it creates another object and plays the same soundtrack twice. How do i overcome this ? NSURL *url = [[NSBundle mainBundle] URLForResource:@"backgroundMusic" withExtension:@"mp3"]; self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; self.backgroundMusic.numberOfLoops = -1; [self.backgroundMusic prepareToPlay]; if

AvAudioPlayer not working?

廉价感情. 提交于 2020-01-07 01:22:28
问题 I create the AVAudioPlayer object and play the music within the scene, if i transition through to another scene and then go back to the original scene it creates another object and plays the same soundtrack twice. How do i overcome this ? NSURL *url = [[NSBundle mainBundle] URLForResource:@"backgroundMusic" withExtension:@"mp3"]; self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; self.backgroundMusic.numberOfLoops = -1; [self.backgroundMusic prepareToPlay]; if