sprite-kit

SpriteKit how to create and transition to different scenes (Swift language)

旧时模样 提交于 2019-12-13 04:25:21
问题 I have created a game with sprite kit but at the moment when the game is launched, it goes straight to the game. How can i implement different scenes like a main menu and a game over scene and transition between them either by pressing a label on the screen or by a contact during the game. 回答1: It doesn't seem like you have looked into Apple's documentation. They have an excellent guide for SpriteKit. Also, the tutorials at RayWenderlich.com within the spriteKit category are phenomenal. I

Anchorpoint on SKShapeNode or something else

佐手、 提交于 2019-12-13 04:23:12
问题 I can't figure out how to make the anchorpoint in my SKShapeNode that is probably set to (0.5,0.0) to (0,0) since when my game draws the path the coordinate system is not working right... Thanks for the help 回答1: SKShapeNode does not have an anchorPoint. LearnCocos2D answered on this issue: When you use an image you may need to align it on its node's position. There's no other way to do so but through anchorPoint because the image itself can't be modified (not easily anyway). When you create

how to add a gesture to skView?

对着背影说爱祢 提交于 2019-12-13 04:21:56
问题 I need to add several swipe gestures to my scene on a game. From what I know, this can only be done programmatically, unfortunately I have never added gestures in this way, I have always used IB. I know I need to initialize a gesture recognizer, using initWithTarget:action: and I know how to set its properties, what I don't know is how to make this gesture do stuff. I assume it is through the action parameter @selector but this seems to never get called. Am I doing this wrong? here is what I

Does AVPlayer stop the user's music?

被刻印的时光 ゝ 提交于 2019-12-13 04:13:07
问题 I want to know -- what happens to a user's music when an AVPlayer starts to play? Does nothing happen, does it stop, or does the action cancel itself? If so, how would I check and see if the user is playing music? Apple's Documentation for this confused me. 回答1: Alright, looking up the info for this, it seems that AVAudioPlayer objects only interrupts the user's audio if the app's AVAudioSession 's category is set to Solo Ambient , the default. I saw this answer: App with AVPlayer plays mp4

score label display value overwrites

筅森魡賤 提交于 2019-12-13 04:00:50
问题 When THE score updates, a new score value label overwrites old one on the display, because of this score is just unreadable, how to update new score? here what i got: SKLabelNode *ScoreLabel; NSInteger score = 0; ----------------------------- -(void)Scoring{ score = score +1; ScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"]; ScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame), 960); ScoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score]; [self addChild:ScoreLabel];

Best way to drag Sprites that are attached via SKPhysicsJoints?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 03:59:20
问题 I'm having trouble moving sprites that are attached via an SKPhysicsJoint. I have a touchesMoved method that looks like this: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint positionInScene = [touch locationInNode:self]; CGPoint previousPosition = [touch previousLocationInNode:self]; CGPoint translation = CGPointMake(positionInScene.x - previousPosition.x, positionInScene.y - previousPosition.y); CGPoint newPosition =

didBeginContact - bodyA & bodyB end Contact if one of them hits another category

流过昼夜 提交于 2019-12-13 03:55:28
问题 Here is the deal, I've got a basket, an Apple and an Orange bodies. We are going to drop them into the basket. I also want to know the presence of the Apple inside the basket, so I go ahead and add a didEndContact method. Lets assume the apple is already inside the basket. Now I drop the Orange in the basket, everything works fine until the Orange hits both the Apple and the surface which is the basket. As soon as the Orange hits the Apple while it's seating in the basket, Apple category ends

How to move from view controller to skscene

谁都会走 提交于 2019-12-13 03:48:19
问题 I want to present SKScene from a UIViewController in swift language, I'm developing a game in iOS , the menu is a UIViewController and the game is in SpriteKit, I need to move from the menu ( UIViewController ) to the game ( SKScene ) upon pressing a button. How can I do something like that ? 回答1: Like @Ron Myschuk said you should consider moving your menu to SpriteKit . If you want to use UIKit you will need to communicate the SKScene with the UIViewController (I guess that is your problem).

How to make one body stick to another moving object in SpriteKit

て烟熏妆下的殇ゞ 提交于 2019-12-13 03:43:39
问题 I have an object moving along the X-axis, while the other body rests. After a collision is made, I wish the resting object move along with the moving object. I use this code to move the first body: SKAction* moveBlock = [SKAction moveByX:-distanceToMove y:0 duration:0.01 * distanceToMove]; SKAction* removeBlock = [SKAction removeFromParent]; _moveBlocksAndRemove = [SKAction sequence:@[moveBlock, removeBlock]]; and in the collision detection I have tried to set a friction: if (firstBody

physics body not inline with shape?

a 夏天 提交于 2019-12-13 03:37:44
问题 for some reason when i apply a physics body around the skshapenode it places the physics body more to the left and downwards of the actual shape even though the parameters of the physics body comes from the shape. does anyone know why? thanks. -(SKShapeNode*) createGround1 { //create a rectangle ground1 = [SKShapeNode shapeNodeWithRect:CGRectMake(0, 0, 300, 19)]; ground1.position = CGPointMake(800, 500); //applies physics to rectangle ground1.physicsBody = [SKPhysicsBody