sprite-kit

sprite kit - one node with two physics body

微笑、不失礼 提交于 2019-12-05 22:05:12
It's possible for one node having two physics body path ? how to do that ? I want to create a node that having two (circle) physics body on sides of the node. If it's not possible, is there are any tricks to achieve that ? thanks Mike S You want to use [SKPhysicsBody bodyWithBodies:...] . From the docs : The shapes of the physics bodies passed into this method are used to create a new physics body whose covered area is the union of the areas of its children. These areas do not need to be contiguous. If there is space between two parts, other bodies may be able to pass between these parts.

Posting score to facebook

混江龙づ霸主 提交于 2019-12-05 21:26:19
I created an app in SpriteKit with xcode where when the game is over, it shows you your score, and I want to add the feature to post your score to facebook. Pretty much all my code is in MyScene.m where it can't access presentViewController . Only my ViewController.m file can access that, so I tried calling a instance method in Viewcontroller from Myscene.m but I can't find a way to do that. The only way I have found calling methods from other files is using +(void) which is a class method I think. Myscene.m: if (location.x < 315 && location.x > 261 && location.y < 404 && location.y > 361) { /

SpriteKit - Nodes adjusting position a tiny bit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:25:07
I have a number of individual nodes (tiles) that make up the background of my game. They're each 32x32p, and are positioned next to each other to form floor/ roof/ obstacles. I load a map from a JSON-file, and position the nodes on a background-layer/node based on the contents of the JSON-file when the scene is initialized. This is working fine, however, I'm experiencing some bugs when moving the background layer/ the physics engine is doing its thing. Some of the nodes move 1 point/pixel away from each other, creating a gap between them. And since the background is a different color, this

Make edges of SKSpriteNode look smooth after rotation

本秂侑毒 提交于 2019-12-05 21:22:40
I create a SKSpriteNode like that: var shape:SKSpriteNode = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(CGFloat(sizeOfShape), CGFloat(sizeOfShape))) How can I achieve, that a SKSpriteNode has still smooth edges, after I've rotated it. Currently, it looks like that: As you see, the edges are jagged. 来源: https://stackoverflow.com/questions/25532760/make-edges-of-skspritenode-look-smooth-after-rotation

How can I find the 'safe region' for iPhone size if I am creating my app using iPad size?

牧云@^-^@ 提交于 2019-12-05 21:15:54
问题 I am creating a game and want to use the iPad size settings (landscape: 1024x768). From what I've learnt, using the iPad settings will crop out part of the height only on an iPhone. Say I have a 2048x1536 background image for iPad (1024x768) and a 2208x1242 image for iPhone 6+ (736x414), i. how can I determine the 'safe region' from the iPad that will appear on the iPhone 6+ both point and pixel wise? ii. will the 'safe region' for the iPhone 6+ be the same as the iPhone 6 (667x375) with a

Why CGPath and UIBezierPath define “clockwise” differently in SpriteKit?

荒凉一梦 提交于 2019-12-05 20:36:13
In SpriteKit, the clockwise direction is reversed for UIBezierPath but not for CGPath . For example, if I have do { let path = CGPathCreateMutable() CGPathAddArc(path, nil, 0, 0, 10, 0, CGFloat(M_PI_2), true) let node = SKShapeNode(path: path) node.position = CGPoint(x: self.size.width/2, y: self.size.height/2) self.addChild(node) } do { let path = UIBezierPath() path.addArcWithCenter(CGPoint(x: 0, y: 0), radius: 10, startAngle: 0, endAngle: CGFloat(M_PI_2), clockwise: true) let node = SKShapeNode(path: path.CGPath) node.position = CGPoint(x: self.size.width/2, y: self.size.height/2 - 100)

SpriteKit: run action while scene is paused

五迷三道 提交于 2019-12-05 20:18:07
问题 I have a button to pause the game on my code. What I want is that pausing the game with that button makes a message that says "Paused" to appear. However, since the scene is paused, the message does not appear. What I have right now is a SKLabelNode with the alpha on 0.0 at the beginning and when the user pauses the game, it changes to 1.0 with fadeInWithDuration(). Then when the user presses the button again, it changes back to 0.0 with fadeOutWithDuration(). The problem is that the SKAction

AVAudioPlayer sound not playing

六眼飞鱼酱① 提交于 2019-12-05 19:55:12
问题 In iOS 8/Xcode 6 I had a function that included a sound effect. It no longer works in iOS 9 after changing the code multiple times. This is what I've tried: Original: let bangSoundEffect = SKAction.playSoundFileNamed("Bang.mp3", waitForCompletion: false) runAction(bangSoundEffect) Other attempt: self.runAction(SKAction.playSoundFileNamed("Bang.mp3", waitForCompletion: false)) Also: func playRocketExplosionSound(filename: String) { let url = NSBundle.mainBundle().URLForResource( filename,

Why does [NSSet containsObject] fail for SKNode members in iOS8?

老子叫甜甜 提交于 2019-12-05 19:52:23
Two objects are added to an NSSet , but when I check membership, I can't find one of them. The test code below worked fine in iOS7 but fails in iOS8. SKNode *changingNode = [SKNode node]; SKNode *unchangingNode = [SKNode node]; NSSet *nodes = [NSSet setWithObjects:unchangingNode, changingNode, nil]; changingNode.position = CGPointMake(1.0f, 1.0f); if ([nodes containsObject:changingNode]) { printf("found node\n"); } else { printf("could not find node\n"); } Output: could not find node What happened between iOS7 and iOS8, and how can I fix it? Karl Voskuil SKNode 's implementations of isEqual

Swift convenience initializer extension for SKPhysicsBody

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 19:43:59
extension SKPhysicsBody { /// anchorPoint version of init(rectangleOfSize:center:) convenience init(rectangleOfSize s: CGSize, withAnchorPoint anchorPoint: CGPoint) { var center = CGPoint() center.x = (s.width / 2) - ( s.width * anchorPoint.x) center.y = (s.height / 2 ) - ( s.height * anchorPoint.y) self.init(rectangleOfSize: s, center: center) } } I got this error on runtime -[PKPhysicsBody initWithRectangleOfSize:withAnchorPoint:]: unrecognized selector sent to instance 0x7f9b03c4fff0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PKPhysicsBody