sprite-kit

move one dynamic body relatively to other dynamic body

我怕爱的太早我们不能终老 提交于 2019-12-18 09:27:29
问题 I faced with some problem which I can't find solution for. I have swinging platform (body1) and hero (body2) standing on it. Platform is swinging so hero moving right and left on the platform. In the beginning I want hero to just stand on the platform without changing it's position relatively to platform. I achieved that by adding SKPhysicsJointFixed joining the platform and the hero. Then in some moment in the game I want hero to run along the platform which means that Y should remain the

How do I transfer the user's score to another scene in Swift and SpriteKit?

こ雲淡風輕ζ 提交于 2019-12-18 09:26:04
问题 I have three scenes, a MainMenu Scene, A GamePlay Scene, and a GameOver Scene. The user gets its score in the gameplay scene, and I'm wanting to transfer that score over to the GameOver scene. How can I do this? (If you need my code or more information, just ask!) 回答1: You can use NSUserDefaults class as an easiest solution... In your GameplayScene you set score into persistent storage. let defaults = NSUserDefaults.standardUserDefaults() defaults.setInteger(score, forKey: "scoreKey")

Physics detecting collision multiple times

帅比萌擦擦* 提交于 2019-12-18 09:09:20
问题 When the ball collides with the cup, the score should increase by 1. However it currently increases by 1, 3 or sometimes 4 which means the collision is being detected multiple times. I think I must be checking for collisions incorrectly: let ballCategory : UInt32 = 0x1 << 0 let cupCategory : UInt32 = 0x1 << 1 And in my didMoveToView : //Set physicsBody of scene to a physics body that borders the screen self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame) physicsWorld.contactDelegate

How to subclass NSOperation in Swift to queue SKAction objects for serial execution?

99封情书 提交于 2019-12-18 08:32:44
问题 Rob provided a great Objective-C solution for subclassing NSOperation to achieve a serial queuing mechanism for SKAction objects. I implemented this successfully in my own Swift project. import SpriteKit class ActionOperation : NSOperation { let _node: SKNode // The sprite node on which an action is to be performed let _action: SKAction // The action to perform on the sprite node var _finished = false // Our read-write mirror of the super's read-only finished property var _executing = false /

SKPhysicsBody avoid collision Swift/SpriteKit

元气小坏坏 提交于 2019-12-18 07:23:34
问题 I have 3 SKSpriteNodes in my Scene. One bird , one coin and a border around the scene. I don't want the coin and the bird to collide with each other but withe the border . I assign a different collisionBitMask and categoryBitMask to every node: enum CollisionType:UInt32{ case Bird = 1 case Coin = 2 case Border = 3 } Like so: bird.physicsBody!.categoryBitMask = CollisionType.Bird.rawValue bird.physicsBody!.collisionBitMask = CollisionType.Border.rawValue coin.physicsBody!.categoryBitMask =

How to make my sprite kit scene appear above a UIView?

送分小仙女□ 提交于 2019-12-18 06:48:43
问题 I've done some searching but haven't found anything directly addressing my issue: I have an SKScene with several SKNodes each with SKSpriteNode objects for my game, and I am using a background UIImageView (there are some things I need to do with background that cannot be reasonable done with sprite kit - to my knowledge at least); the problem I'm having is that the UIImageView appears above everything and I can't see my game objects. In my view controller (.m file) I have the following code

IOS 8 iPad App Crashes When UIActivityViewController Is Called

江枫思渺然 提交于 2019-12-18 06:07:00
问题 When a UIActivityViewController is called on the iPhone in this app, it works perfectly, but when called on a iPad, the app crashes. Below is the code I used: func shareButtonPress() { //when the share button is pressed, default share phrase is added, cropped image of highscore is added var sharingItems = [AnyObject]() var shareButtonHighscore = NSUserDefaults.standardUserDefaults().objectForKey("highscore") as Int! sharingItems.append("Just hit \(shareButtonHighscore)! Beat it! #Swath")

How to increase (animate) the width of the square on both ends?

空扰寡人 提交于 2019-12-18 05:49:07
问题 I have created a square that is 40x40, as shown above. I have a 4x40 strip that I'd like to use to animate (increase) the width of my square till it takes the the width of the whole screen within a second, regardless of the square's position. Quite similar to that of a progress bar loading on both sides. UPDATE I forgot to mention that the square is a physics body, hence the physics body must also increase as the sprite increases. 回答1: What you want to do is use SKAction.scaleXTo to achieve

Swift: How to handle view controllers for my game

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 05:23:14
问题 i have a general question about view controllers and how to handle them in a clean way when i develop a SpriteKit based game. What i did so far: Use storyboard only for defining view controllers SKScene's are presented in each view controller (Home, LevelSelection, Game) by presentScene in each view controller i call performSegueWithIdentifier with the identifier i defined in the storyboard between the view controllers all the content i show programmatically using SKSpritenode etc. on the

Multiple skshapenode in one draw?

假如想象 提交于 2019-12-18 05:23:07
问题 Hi I have drawn skshapenodes connecting the nodes in my graph for my visual a* representation. for(int x=0; x<64; x++) { for(int y=0; y<48; y++) { PathFindingNode *node = [[gridToDraw objectAtIndex:x] objectAtIndex:y]; for(int i=0; i< node.connections.count; i++) { PathFindingNode *neighbor = [node.connections objectAtIndex:i]; SKShapeNode *line = [SKShapeNode node]; CGMutablePathRef pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(pathToDraw, NULL, node.position.x, node.position.y);