sprite-kit

Sprite Kit: changing zRotation in DidBeginContact

元气小坏坏 提交于 2019-12-11 11:38:59
问题 SKSpriteNode *_node; - (void)didBeginContact:(SKPhysicsContact *)contact { _node.alpha = 0.5; //this works _node.zRotation = 0.5; // this doesn't work } Any ideas why zRotation doesn't work? I tried doing NSLog and it gives the right zRotation but the screen is not showing. 回答1: Have a look at what the runloop looks like for SpriteKit. Nothing is drawn until after physics are simulated. So even though you are setting the zRotation manually it is probably overridden by the physicsBody and set

Sprite Kit - Notifier that a node is leaving the screen

末鹿安然 提交于 2019-12-11 11:36:14
问题 Is there a event/notification in Sprite Kit that tells me when a node is leaving the screen? Lets say I want a coloured circle to appear on top when it left the screen at the bottom. Which means I need to know when it is leaving the screen. 回答1: Sprite kit does not generate a notification when a sprite leaves screen. You will need to add your own test. Here's an example... - (void) update:(NSTimerInterval)currentTime { CGPoint newPosition = CGPointMake(node.position.x, node.position.y); if

Static Physics body still moving with contact

走远了吗. 提交于 2019-12-11 11:23:49
问题 Hello I have a physics body created within sprite kit editor, here are the settings I've set for it: The problem is, it isn't acting "static". If another physics body bumps into it "weirdly" (for lack of a better description) it often glitches, flying all over the screen, or when I had it pinned, rotating around the pinned location. -Shouldn't this act static and never move, unless it is explicitly moved in code? I need it to have an alpha mask physics body and stand completely still (it is

Massive fps drops when AVAudioPlayer ist triggered repeatedly (Sprite Kit)

蹲街弑〆低调 提交于 2019-12-11 10:48:09
问题 I am creating an iOS-Game in Sprite Kit in which you can fire a water gun. As long as the water gun is fired, a slash-sound is played. Since I implemented this feature, I have massive fps-problems when the sound effect ist triggered repeatedly with the touches-began-method. Is there any possibility to fix that issue? @property (nonatomic) AVAudioPlayer *splashSound; -(id)initWithSize:(CGSize)size { NSError *error3; NSURL *splashURL = [[NSBundle mainBundle] URLForResource:@"splash"

Center SKSpriteNode during pinch

为君一笑 提交于 2019-12-11 10:35:19
问题 I have implemented zoom/pinch on my SKScene with the selected answer in this thread: Zooming an SKNode inconsistent I am now attempting to get the hero character to stay centered (smoothly) during a pinch or zoom action because if I don't, the heroNode will disappear off the screen quickly. I have a centerHero method which I can call when I want, and it works quite well, but when I call this method at the end of the pinch handler the effect is very, very jerky. Here is the pinch handler: -

SKNode failing to find childNodeWithName:

旧城冷巷雨未停 提交于 2019-12-11 10:29:29
问题 I am searching for an SKNode in an SKScene by using the childNodeWithName: method. To set the name I am using an NSManagedObjectID 's URI string representation, obtained like so: [[managedObjectID URIRepresentation] absoluteString]; This gives a node name of: x-coredata://0856426F-EA66-4D28-A88A-FF49225F69B6/Object/p4 However, the childNodeWithName: method returns nil. The node is clearly present when inspecting in the debugger, along with two other nodes: <__NSArrayI 0x9933eb0>(

SpriteKit - Pause screen doesn't show when didBecomeActive

元气小坏坏 提交于 2019-12-11 10:06:30
问题 My pause system works perfectly from inside the game, and also when the app moves to the background and then becomes active again the game stays paused, but my problem now is when it becomes active my pause screen doesn't show. AppDelegate: func applicationDidBecomeActive(application: UIApplication) { NSNotificationCenter.defaultCenter().postNotificationName("Pause", object: nil) } ViewController: override func viewDidLoad() { super.viewDidLoad() let scene = GameScene() // Configure the view.

Spritekit top down turning character movement

旧时模样 提交于 2019-12-11 09:59:01
问题 I'm creating a top down 'racer' game if you will in Spritekit. However, I'm already stuck in creating the gameplay. You control a car from a top down view which is always driving at a constant speed. The player can press two buttons to turn the car left or right. The speed has to remain constant, but the zRotation of the car has to change. Changing the zRotation isn't the problem, but defining the new velocity of the car is. I'm currently working with Vectors, so say every time the player

Optional unwrapping SKPhysics error

让人想犯罪 __ 提交于 2019-12-11 09:49:54
问题 Before I'm crucified with downvotes let me say I have done research into this and I still cannot understand why I am getting this error. I have a core that the player is trying to defend and you can shoot little lasers out from it to defend against incoming meteors. Well, I have everything set up and working (most of the time anyways), but every once and while when a laser hits a meteor and my collision handling function tries to remove the shot node and meteor node, it throws this error:

Sprite Kit leaks don't make sense

我的梦境 提交于 2019-12-11 09:35:38
问题 I have been running Instruments to see why my SKScene won't deallocate and getting "leaks" that don't make any sense. One of the "leaks" is on a scene that properly deallocates and points to this: border.path = path; As the line causing the leak but the very next line is: CGPathRelease(path); border.lineWidth = 1.0f; border.strokeColor = [SKColor yellowColor]; [border setAlpha:0.0f]; [border runAction:[SKAction fadeAlphaTo:1.0f duration:0.2f]]; [self addChild:border]; So you can clearly see