sprite-kit

SKPhysicsBody Change Center of Mass

牧云@^-^@ 提交于 2019-12-14 01:29:54
问题 I am currently working on a game where I have a picture of a kind of cylindrical object, and I make an SKPhysicsBody with the following: self.oval.node.physicsBody = SKPhysicsBody(texture: self.oval.node.texture, size: self.oval.node.size) This method creates a nice shape around the node, however, the center of gravity is way off... It balances on the tip of the oval. Is there anyway to change that so it balances where the heaviest part should in theory be? Thanks! 回答1: The center of mass can

SpriteKit: Howto make holes in layer with blendMode

限于喜欢 提交于 2019-12-14 01:02:17
问题 I have a simple scene with some elements added to it. Now i want focus on a specific element with a mask a cut a whole at the same position as the element I want to focus on. Very similar to what we can see on some games when they are started first time showing some kind of tutorial. Basically I am adding a fullscreen layer with alpha=0.7 (so user still see all the content) but then add a circle at a specific position as this layers child and set blendMode= . Subtract so it "cuts" out a

SpriteKit / Swift - How to check contact of two nodes when they are already in contact

泪湿孤枕 提交于 2019-12-14 00:27:52
问题 In my game, when the game begins, some nodes are already in contact but I don't find how to detect these contacts. I only succeed to detect contacts that happen when nodes are moving and getting in contact during the game using the function didBeginContact. Anyone has an idea please how to detect these contacts? Here is my didBeginContact if needed: func didBeginContact(contact: SKPhysicsContact) { var firstBody: SKPhysicsBody var secondBody: SKPhysicsBody if contact.bodyA.categoryBitMask ==

didBecomeActive un-pauses game

▼魔方 西西 提交于 2019-12-13 21:12:38
问题 I am pausing my game with a willResignActive notification, and it seems to pause the game, but when didBecomeActive is called, it seems to un-pause on its own. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResign) name:UIApplicationWillResignActiveNotification object:NULL]; - (void) applicationWillResign { self.scene.view.paused = TRUE; NSLog(@"About to lose focus"); } How do I get it to stay paused? Do I actually need to pause it in my AppDelegate?

SKLabelNode creates black line and not showing text on iPhone4

筅森魡賤 提交于 2019-12-13 20:23:33
问题 I am loading different texts into a SKLabeNode it works fine on iPhone5, simulator, etc... but on iPhone4 I sometimes just get a black line, instead of the text. It is weird that always the same texts are generating the failure, but I cannot figure out what is happening. The code is: ButtonText=@""; ButtonLabel=[SKLabelNode labelNodeWithFontNamed:@"Marker Felt"]; ButtonLabel.fontSize=46; ButtonLabel.text=ButtonText; ButtonLabel.position=CGPointMake(0, 0); ButtonLabel.verticalAlignmentMode

Calling method with animation from update function in sprite kit

天涯浪子 提交于 2019-12-13 19:57:08
问题 so I have this method: -(void)levelLabel { SKLabelNode *levelOne = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"]; levelOne.fontSize = 25; levelOne.fontColor = [SKColor whiteColor]; levelOne.text = @"Level 1"; levelOne.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2); [self addChild:levelOne]; SKAction *stageNumberIn = [SKAction fadeInWithDuration:1.0]; SKAction *stageNumberOut = [SKAction fadeOutWithDuration:1.5]; SKAction *remove = [SKAction removeFromParent];

Using waitForDuration() in spriteKit swift

江枫思渺然 提交于 2019-12-13 19:54:44
问题 I wanted to wait 2 seconds between generation nodes. So I wrote this code: override func update(currentTime: CFTimeInterval) { let releaseNodes = SKAction.sequence([SKAction.runBlock(self.generateNode), SKAction.waitForDuration(2)]) self.runAction(releaseNodes) } But it doesn't work. It's generating nodes as crazy. (like 20 in seconds). How can I handle with it? Can anyone help me, please? Edit: Here is the self.generateNode block func generateNode(){ var node: SKSpriteNode = SKSpriteNode

SpriteKit SKPhysicsBody broken collisions

有些话、适合烂在心里 提交于 2019-12-13 19:44:03
问题 I have a SKSpriteNode which has a static body, generated from concave path with edgeChainFromPath . Let's call this node a house . I also have another kind of SKSpriteNode s which have a dynamic square body, generated with rectangleOfSize . Let's call this node a box . In my scene, the boxes are thrown aka impulsed into the house and since both of them have bodies, the boxes should collide with the house and bounce away. I'm scrolling the scene and therefore creating new instances of EXACTLY

Changing the initial scene in spritekit

蓝咒 提交于 2019-12-13 19:39:54
问题 Aim: To load the scene in Instructions1.swift file as the first scene of the game. What I did : So I created 2 new files in my project : Instructions1.sks and Instructions1.swift Then in GameViewController.swift , I changed the viewDidLoad as follows : override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene.unarchiveFromFile("Instructions1") as? GameScene { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true /* Sprite

Basic Swift SpriteKit Collisions using PhysicsBodys

社会主义新天地 提交于 2019-12-13 17:42:50
问题 The problem: I seem to be having a little trouble getting my player to collide with a coin, and adding +1 to a coinLabel upon the collision. The player should continue moving after coming in contact with the coin. What I have now: With the code I have now, the player travels through the coin, but there is no collision that takes place and +1 isn't added to the coin label. I am still learning the swift language, so I appreciate any help that is given. Code: struct ColliderType { static let