sprite-kit

Sprite Kit: create node only once for all scenes

核能气质少年 提交于 2019-12-17 16:11:16
问题 Normally in a sprite kit game, when a new scene presented, all the nodes in the old scene and their content removed automatically. Now what is, if a node like "HUD" should be not removed? Is there any way in sprite kit to create a node only once and use it in all scenes without removing and creating it again and again every time in every new scene? There must be a technique that makes it possible. that's a serious sprite kit design problem, if it is not possible. But I don't think so. The

How to transition scenes in Swift

大兔子大兔子 提交于 2019-12-17 15:57:16
问题 In Objective-C, using Sprite-Kit, I would successfully use something like the following code in Objective-C to bring up a new scene if ([touchedNode.name isEqual: @"Game Button"]) { SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:1.0]; GameScene *newGameScene = [[GameScene alloc] initWithSize: self.size]; // Optionally, insert code to configure the new scene. newGameScene.scaleMode = SKSceneScaleModeAspectFill; [self.scene.view presentScene:

ios Sprite Kit screengrab?

旧城冷巷雨未停 提交于 2019-12-17 15:32:56
问题 I am trying to get a screen grab of a view that has a SKScene in it. The technique I am using is: UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); This works great with normal UIViews, but for whatever reason it is ignoring all the sprites in the SKScene. I'm not sure if this is a bug, or if Sprite Kit's

Sprite-Kit registering multiple collisions for single contact

﹥>﹥吖頭↗ 提交于 2019-12-17 13:27:46
问题 OK - I’m sure this is a duplicate and that Whirlwind or KnightOfDragons has posted a solution, but I can’t find it. I’m writing a clone of Space Invader in Swift using Sprite-Kit. The problem I have is that when a invader bomb hits my ship, the code sometimes registers 2 or 3 collisions, immediately ending the game. Here’s the section of ‘didBeginContact’ that handles the bomb/ship collision: case category.bomb.rawValue | category.ship.rawValue: print("Bomb hit ship!") let bomb = contact

How can I make a function execute every second in swift?

那年仲夏 提交于 2019-12-17 08:56:09
问题 I want to add a score to the top of my scene in the game I am working on. The score is going to based on how long you last, and will increase every second. Thanks for the help in advance! import SpriteKit class easyScene: SKScene { let scrollBarEasyBottom = SKSpriteNode(imageNamed: "scrollBarEasyBottom") let scrollBarEasyTop = SKSpriteNode(imageNamed: "scrollBarEasyTop") let ball = SKSpriteNode(imageNamed: "ball") var origSBEBpositionX = CGFloat(0) var origSBETpositionX = CGFloat(0) var

iOS Simulator games run very slow (low fps)

可紊 提交于 2019-12-17 04:31:05
问题 Diving into sprite kit (xcode 5). There are two example programs I'm working with, 1. the default spaceship example that's included when creating a new project and 2. the Adventure Game, which I downloaded. Running these examples within the iOS Simulator (doesn't seem to matter which). The frame rate for each is absolutely abysmal. If I add only 30 spinning space ships in the space ship / hello world example, the FR rapidly drops from 60 FPS to (ug) 12 FPS. The Adventure Game example, again,

How to move enemy towards a moving player?

亡梦爱人 提交于 2019-12-17 02:37:58
问题 I am creating a simple sprite kit game that will position a player on the left side of the screen, while enemies approach from the right. Since the player can be moved up and down, I want the enemies to "smartly" adjust their path towards the player. I tried removing and re-adding the SKAction sequence whenever the player moves, but the below code causes the enemies to not show at all, probably because its just adding and removing each action on every frame update, so they never have a chance

Xcode 6 - xcassets for universal image support

半世苍凉 提交于 2019-12-17 02:26:57
问题 Currently working on a universal SpriteKit project. I'll be supporting the following devices: iPhone 4/s, iPhone 5/c/s, iPhone 6, iPhone 6+ iPad non-ret, iPad retina I am confused on the iPhone part. I already have 4 versions for my background sprite for the 4 different screen resolutions of the iPhones. But which goes to which? I know the 3x is for the 6+, and I think the 5/c/s goes to the Retina 4 2x, but I do not know where the iPhone4/s, and 6 go. Anyone know? Side note, when I create a

Dealing with different iOS device resolutions in SpriteKit

核能气质少年 提交于 2019-12-17 01:39:50
问题 I'm playing around with SpriteKit in Xcode 6, iOS 8 beta 5. Everything is all laid out and working perfectly on the iPhone 4S simulator, however when switching to the 5S, the elements at the bottom of the screen are cut off. It was to my understanding that the bottom left corner of the iPhone screen should be CGPoint(0, 0) but after checking the location by printing the coordinates to the console that the lowest point of the left corner I could click was around (5, 44). Is there something

Add boundaries to an SKScene

耗尽温柔 提交于 2019-12-14 04:20:33
问题 I'm trying to write a basic game using Apple's Sprite Kit framework. So far, I have a ship flying around the screen, using SKPhysicsBody. I want to keep the ship from flying off the screen, so I edited my update method to make the ship's velocity zero. This works most of the time, but every now and then, the ship will fly off the screen. Here's my update method. // const int X_MIN = 60; // const int X_MAX = 853; // const int Y_MAX = 660; // const int Y_MIN = 60; // const float SHIP_SPEED = 50