sprite-kit

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

别来无恙 提交于 2019-12-22 10:08:15
问题 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 =

Sprite Kit Table View

為{幸葍}努か 提交于 2019-12-22 10:07:51
问题 I'm trying to build a scrolling table of game center scores in an SKScene. Is there a way to use sprite kit and storyboards/xibs? [self addChild:customTable] on an SKScene doesn't seem to work. 回答1: UIKit elements like UITableView , UIView , etc cannot be used as children of SpriteKit nodes. You can place a UITableView on top of a SKView / UIView but that comes out as crude. I would suggest you use a normal UIViewController to display your Game Center scores. However, if you still need to

How to stop/cancel playSoundFileNamed in Swift?

余生长醉 提交于 2019-12-22 10:01:55
问题 I'm trying to make a button, which is when pushed - the sound is played, and when pushed again - the sound would stop. I'm using playSoundFileNamed: runAction: withKey: and removeActionForKey , but it doesn't work. The other question I have is if there is a way not only to stop the sound, but also to pause it (so that it will start from the same part it was paused, NOT from the beginning). I've seen a similar topic at stack overflow, but yet didn't find an answer on my question yet. Thank you

Prevent player from falling through the ground - Sprite Kit

六眼飞鱼酱① 提交于 2019-12-22 09:33:28
问题 I've been trying to work on a simple Sprite Kit game that involves dodging red balls. I'm using the built-in gravity mechanism, but I'm having trouble preventing the player from falling through the ground. I've looked up a solution (set ground.physicsBody.dynamic = NO), but the player still falls through. What exactly do I need to do? Edit: The green and brown texture is the ground. Right now the player is set to not being dynamic, so it is 'flying' Here is my code in the MyScene.m file: // /

sprite kit - one node with two physics body

落爺英雄遲暮 提交于 2019-12-22 09:33:11
问题 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 回答1: 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

iOS7 SKScene how to make a sprite bounce off the edge of the screen?

六眼飞鱼酱① 提交于 2019-12-22 09:22:13
问题 I'm building a game with balls bouncing within the iPad's screen. Similar to a Pong game. I see that SKScene's SKPhysicsWorld has gravity property, and also controls how objects collide with each other. Is there some way I can automatically detect if a sprite's edge has collided with the screen's edge, so it can bounce off that? Or do I need to write my own collision code? 回答1: You don't need to write much code to make the ball bounce off the edge of the screen. the physics environment can

OpenAL vs AVAudioPlayer vs other techniques for playing sounds

巧了我就是萌 提交于 2019-12-22 08:51:53
问题 I know that OpenAL is fast library but it doesn't support any compressed audio format and it's not so easy to use... AVAudioPlayer is not so fast, but supports wide range file formats, as well as compressed formats like mp3. Also there is an SKAction class which can play a sound, as well as SystemSoundID... I have few questions: What would be a preferred way/player/technique to play : sound effects(multiple at the time)? sound effects which can be sometimes repeated after small time delay

Swift physicsbody edge recognition issue

陌路散爱 提交于 2019-12-22 08:39:23
问题 The following code recognizes the bottom and top edge of the scene and the ball bounces off as expected. However, the left and right edges of the scene are breached all the time. The ball goes off screen and then eventually returns back if enough force is applied. It is as if the edges of the scene are beyond the edges of the iphone simulator window. Can someone help? Thanks. import SpriteKit class GameScene: SKScene { override func didMoveToView(view: SKView){ self.physicsBody =

ScrollView in SpriteKit

你。 提交于 2019-12-22 08:28:45
问题 I have found a few other questions and answers similar to this, but none of them quite work perfect for me. My vision is to have a horizontal scrollable view at the bottom of the screen where I can scroll through what will look like cards in a hand. Ideally, I could eventually make the card in the middle scaled up a bit and give it a highlighted look to show the user which card is selected. Even better would be if I could figure out how to keep the scroll view resizing to fir the number of

How to set the background image for a SKScene?

白昼怎懂夜的黑 提交于 2019-12-22 08:27:15
问题 Since currently it is not possible to set the color to of a SKScene to clearColor , by doing -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor clearColor]; } return self; } As seen here: LINK Then how can one set the background image for a SKScene ? Please be as specific as possible, sample code would be great! 回答1: Use an SKSpriteNode centered in the scene: -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { //