sprite-kit

Increase jump height on longer touch until maximum height

跟風遠走 提交于 2019-12-06 01:37:22
I'm using the following methods to make my character jump: override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { if onGround && !gameOver { self.character.physicsBody?.applyImpulse(CGVectorMake(0, 75)) self.onGround = false } } override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { } This works fine, but I want to make the character jump a certain height based on the length of the touch until a maximum. I've tried something with frame durations but this didn't work. How can I make the character jump based on touch length until a maximum height?

Drag SKSpriteNode based on touch location

好久不见. 提交于 2019-12-06 01:37:03
问题 I am trying to drag a sprite in the y axis but make the sprite "stick" to the users finger depending on where the touches began on the node. The sprite is currently dragging but it seems to be snapping the anchorpoint of the sprite to the touch location within the node. Im assuming it has something to do with getting the location within the node by doing [touch locationInNode:selectedNode]; but I am unsure where to go from there. Here is my current code. -(void)touchesMoved:(NSSet *)touches

Creating levels in an iOS Sprite Kit Game

那年仲夏 提交于 2019-12-06 01:23:37
问题 I'm creating a game and I want it to have a scene with levels to select, then have the levels to play. I was just wondering how to go about creating the levels and saving when a user has gotten to that level. I was thinking to create a BOOL in the ViewController.h and call it in each scene, i.e. LevelCompleted = YES; then use that bool when the player is trying to play a new level or replay a previous level Or, Do I have a BOOL in each scene, then import each scene's header file into the

How to stop/cancel playSoundFileNamed in Swift?

 ̄綄美尐妖づ 提交于 2019-12-06 01:03:34
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 in advance. import SpriteKit import AVFoundation var firesoundon = false private var

SpriteKit. Stop rotate Texture with CameraNode

无人久伴 提交于 2019-12-05 22:52:25
I'm doing a little game where the car goes around a planet. The camera is always directed to the machine at an angle of 90 degrees from the planet. I encountered a problem that the texture of the planet rotates along with the camera. If the camera does not rotate, the texture is behaving as it should. How do I fix this? Create planet from beizerPath: planetTexture = SKTexture(imageNamed: "asanoha") planet = SKShapeNode(path: beizerPath.cgPath) planet.position = CGPoint(x: 0, y: 0) planet.zPosition = 10 planet.physicsBody = SKPhysicsBody(polygonFrom: beizerPath.cgPath) planet.physicsBody?

SKPhysicsBody with restitution 0 still bounces

一个人想着一个人 提交于 2019-12-05 22:43:10
I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]]; block.position = CGPointMake(160, 300); block.physicsBody = [SKPhysicsBody

How to loop music with SKAction?

≯℡__Kan透↙ 提交于 2019-12-05 22:37:30
I want to loop my background music with an SKAction but the music stops after one row when I switch to an other scene. Is there a way to start the loop and keep playing it over different scenes? Right now the code is placed in the init method of MyScene - is that the correct place? Maybe didFinishLaunchingWithOptions? Here is what I've tried: if (delegate.musicOn == YES && delegate.musicIsPlaying == NO) { SKAction *playMusic = [SKAction playSoundFileNamed:@"loop.wav" waitForCompletion:YES]; SKAction *loopMusic = [SKAction repeatActionForever:playMusic]; [self runAction:loopMusic]; delegate

Why can't I add a SKScene to another SKScene?

荒凉一梦 提交于 2019-12-05 22:21:58
I'm trying to make this SKScene appear in the middle of the scene at the end of the game, so that the previous scene is still visible in the background (similar to that of the ending of flappy bird). This is an image of how I want it to appear: So far this is the code I've made: in the game scene: -(void)dieFrom:(SKNode*)killingDebris { _touched = YES; if (_touched == YES) { beatLevel = YES; NSLog(@"touched"); [self runAction:[SKAction sequence:@[ [SKAction runBlock:^{ [_goodSquare removeFromParent]; }], [SKAction runBlock:^{ level2Achieved = [[NSUserDefaults standardUserDefaults]

SKAction: How to Animate Random Repeated Actions

和自甴很熟 提交于 2019-12-05 22:12:58
I'd like to run a repeating SKAction but with random values on each repeat. I have read this question here that shows one way to do this. However, I want my sprite's movements to be animated, not simply changing its position. One solution I have come up with is to run a sequence of actions, with the final action calling my move method in a recursive fashion: - (void)moveTheBomber { __weak typeof(self) weakSelf = self; float randomX = // determine new "randomX" position SKAction *moveAction = [SKAction moveToX:randomX duration:0.25f]; SKAction *waitAction = [SKAction waitForDuration:0.15

iOS Swift didBeginContact not being called

早过忘川 提交于 2019-12-05 22:09:06
问题 I have been struggling for the past two days to get two SKSpriteNodes to register a collision and evoke didBegin#contact . I've set their bit masks ' categoryBitMask ', ' contactTestBitMask ' and ' collisionTestBitMask ' for both objects. I've also set the ' dynamic ' property for both to ' true ' initPhysics() seems to set up the physicsWorld okay. All I'm expecting is that didBegin#Contact is called, but it is not //Set up Physicsbody bit masks let playerCarBitMask: UInt32 = 0x1 << 1 let