sprite-kit

Swift - SpriteKit CGPoint Alignment

a 夏天 提交于 2020-01-08 18:03:24
问题 I'm working on a project in swift and I am able to make a sprite. I am trying to make a sprite at a number of different locations. As a test I replaced the code in the game scene to be: class GameScene: SKScene { override func didMoveToView(view: SKView){ let wall = SKSpriteNode(imageNamed: "Wall") wall.position = CGPoint(x: 289, y: 0) } } What I do not understand is this code makes a sprite in the lower left corner. As expected in the y direction only half of the sprite shows, but the x

How to support multiple screen sizes in SpriteKit?

梦想的初衷 提交于 2020-01-08 06:37:04
问题 I want to make universal game that support all iOS devices , beside making the project how to make my game support all screen sizes is there is a way to detect the screen size by code and change the graphic and the code according to the size , and what should the resolution of the graphics for each device ? 回答1: Use this code to determine the width and height of the screen. You can also find out what device is being used. struct ScreenSize { static let SCREEN_WIDTH = UIScreen.mainScreen()

Keep SpriteKit scene paused after app becomes active

时间秒杀一切 提交于 2020-01-07 08:29:11
问题 When returning to my App after closing it the applicationDidBecomeActive(application: UIApplication) automatically fires in AppDelegate.swift. This fires a method that handles the paused status of the app: GameViewController().pause(true) The method looks like this: func pause(paused: Bool) { if paused == true { scene?.paused = true print("paused") } else if paused == false { scene?.paused = false print("unparsed") } } When first launching the app the Game is automatically paused which is

Sprite kit skview.showPhysics bug?

旧时模样 提交于 2020-01-07 05:28:22
问题 Here is the code for setting the characters physics body. character.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:character.size]; It works fine, I mean it stays where I want it to but as you can see it displays the character 's physics body in the bottom left of the screenshot (which is the grey box). Is this a bug or can this be fixed? 回答1: I had a similar problem which may or may not solve yours. It looks like you are using some sort of viewport system. Perhaps with a node called

How to check for internet connection before showing an option to view an incentivized app?

瘦欲@ 提交于 2020-01-07 03:52:07
问题 For my current sprite kit game that is coded in OBJECTIVE - C, I want to check for internet connection before providing the user with an option to view an incentivized ad. How would I do this? I only want the option to appear if the user is connected to the internet. 回答1: Step-1) Download the Reachability project from GitHub Project from here. Step-2) Add Reachability.h and Reachability.m files in your project from github project. Step-3) In your viewController.m -> #import "Reachability.h"

add another background image to change background during playing game

╄→尐↘猪︶ㄣ 提交于 2020-01-07 02:21:21
问题 func createBackgrounds() { for i in 0...2 { let bg = SKSpriteNode(imageNamed: "BG Day") bg.name = "BG" bg.zPosition = 0; bg.anchorPoint = CGPoint(x: 0.5, y: 0.5) bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0) self.addChild(bg) } } If I want to add another background image after 2 minutes to BG Night , how can I write coding in swift 2? 回答1: You can use SKAction.runBlock to run some code in the future class GameScene: SKScene { var background: SKSpriteNode? override func

add another background image to change background during playing game

喜欢而已 提交于 2020-01-07 02:21:02
问题 func createBackgrounds() { for i in 0...2 { let bg = SKSpriteNode(imageNamed: "BG Day") bg.name = "BG" bg.zPosition = 0; bg.anchorPoint = CGPoint(x: 0.5, y: 0.5) bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0) self.addChild(bg) } } If I want to add another background image after 2 minutes to BG Night , how can I write coding in swift 2? 回答1: You can use SKAction.runBlock to run some code in the future class GameScene: SKScene { var background: SKSpriteNode? override func

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

How to add a SKSpriteNode to the scene in Swift?

我的未来我决定 提交于 2020-01-06 21:59:33
问题 I tried to subclass SKSpriteNode into GameObject and I would like to instantiate objects outside the game scene class. Here is my GameObject code derived from SKSpriteNode : import SpriteKit public class GameObject: SKSpriteNode { init( texture: SKTexture?, color: UIColor, size: CGSize, position:CGPoint, name:String ) { objectSize = size; objectName = name; objectSprite = texture; //call superclass here super.init(texture: texture, color: color, size: size); self.position = position; }