sprite-kit

SpriteKit not deallocating all used memory

纵饮孤独 提交于 2020-01-12 03:56:08
问题 I have ready many (if not all) articles on SO and other sites about the disasters of dealing with SpriteKit and memory issues. My problem, as many others have had, is after i leave my SpriteKit scene barely any of the memory added during the scene session is released. I've tried to implement all suggested solutions in the articles i've found, including, but not limited to... 1) Confirm the deinit method is called in the SKScene class. 2) Confirm no strong references to the parent VC in the

Run SKActions sequence with different nodes

时光毁灭记忆、已成空白 提交于 2020-01-11 08:50:40
问题 I know that I can create an SKAction.sequence which will run the actions of one node one by one. But how can I do that if I want to do a sequence with different nodes. I'd like to do something like that: Run action from node A wait 2 seconds Run action from node B. 回答1: If both nodes are uniquely named and are children of the same node, you can use runAction:onChildWithName: , as follows: SKAction *action = [SKAction sequence: @[[SKAction runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f)

NSUserDefaults not saving

拟墨画扇 提交于 2020-01-11 05:07:32
问题 I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called) if (![defaults objectForKey:@"obj"]) { difficultyLabel.text = @"Difficulty: Easy"; [defaults setObject:@"Easy" forKey:@"obj"]; } else { difficultyLabel.text = [NSString stringWithFormat:@"Difficulty: %@", [defaults objectForKey:@"diff"]]; } and then when you click on the SKLabelNode to change the difficulty and this code is being called if ([label

Moving SKSpriteNode to location of the touch

◇◆丶佛笑我妖孽 提交于 2020-01-11 04:15:28
问题 Above is an image of my game. A top-down game. Wherever on the screen the player touches, I want the bullets to go to that location with a duration. I also want the player to be able to drag around his finger on the screen, and the same thing happens. So that the player doesn't have to touch the screen everytime he wants to shoot. I've tried some different stuff so far but nothing seems to work. First off, I dont know if I should have a separate function for the bullet. But anyway, this is my

Have particle emitter trail follow finger path in spriteKit

二次信任 提交于 2020-01-11 02:36:09
问题 I have created a particle emitter in Xcode that has quite a lengthy trail. When i move it inside of the particle generator it leaves a trail following my mouse path. some background info on my goal: In my spriteKit game the user drags their finger around the screen to shoot moving objects. I am attempting to create a "Bullet Time" effect where the objects slow down and highlights when the current finger location touches them. When the finger stops moving or they run out of ammo the

How Can I get keyboard input in a SpriteKit Game?

六眼飞鱼酱① 提交于 2020-01-10 04:54:25
问题 I'm a beginner in SpriteKit programming, and have been trying to figure out how to handle input from the keyboard. What I've found so far is that you should subclass NSResponder and implement it like this: @interface AppDelegate : NSResponder <NSApplicationDelegate> -(void)keyUp:(NSEvent *)theEvent; -(void)keyDown:(NSEvent *)theEvent; @end @implementation AppDelegate -(void)keyUp:(NSEvent *)theEvent { NSLog(@"Key Released"); } -(void)keyDown:(NSEvent *)theEvent { NSLog(@"Key Pressed"); } @end

Move a node to finger using Swift + SpriteKit

耗尽温柔 提交于 2020-01-10 04:03:05
问题 UPDATE: I have solved the problem, and figured out a more simplified way to do this then the answer provided. My solution was to make the velocity of the SPACESHIP equal the distance it was from my finger touch. For faster movement, you can multiply this velocity by a constant. In this case, I used 16. I also got rid of setting lastTouch to nil in the touchesEnd event. That way, the ship will still stop even when I release my finger. override func update(currentTime: CFTimeInterval) { /*

Correct way to create button in Sprite Kit?

白昼怎懂夜的黑 提交于 2020-01-09 12:55:11
问题 I'm making a game and I want to have a button. How do I handle tapping it? I use separate class for UI, it is SKSpriteNode that holds all buttons and interface elements, and I don't want Scene to handle those button presses for me in touches began method. As I know we can check for node that is being touched in touches began, so to implement regular button with touch up inside I need to write code in touchesBegan and touchesEnded, this looks like a bit overkill. Or should I use regular

Swift - SpriteKit CGPoint Alignment

余生颓废 提交于 2020-01-08 18:06:51
问题 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

Swift - SpriteKit CGPoint Alignment

末鹿安然 提交于 2020-01-08 18:04:57
问题 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