skaction

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

SKSpriteNode : Handling Collision during SKAction

别说谁变了你拦得住时间么 提交于 2019-12-05 18:40:52
I'm making a little game, and I'm now stuck with the following problem. I'm running an action (followPath type) on a particular node : let followTrack: SKAction = SKAction.followPath(ballPath!.CGPath, duration: ACTION_SPEED) movingBall.runAction(followTrack) But during the animation, if the node collide with another one (like a wall for exemple), the animation stops and there is no collision animation. I tried some things like : func didBeginContact(contact: SKPhysicsContact) { var firstBody: SKPhysicsBody = contact.bodyA var secondBody: SKPhysicsBody = contact.bodyB firstBody.node?

Modify a repeating task sequence while running

拜拜、爱过 提交于 2019-12-04 19:36:50
I am trying to make a repeating task where I can change the delay in which it repeats. Here is the current code I am using: var actionwait = SKAction.waitForDuration(self.wait) var actionrun = SKAction.runBlock({ self.count+=1 if (self.count % 2 == 0 && self.wait > 0.2){ self.wait -= 0.1 actionwait.duration = self.wait } for node in self.children{ if (node.isMemberOfClass(Dot)){ node.removeFromParent() } } var radius = CGFloat(arc4random_uniform(100) + 30) var newNode = Dot(circleOfRadius: radius) var color = self.getRandomColor() newNode.fillColor = color newNode.strokeColor = color newNode

Can I move dynamic physics bodies using SKAction when only contact detection is needed?

ぃ、小莉子 提交于 2019-12-04 16:26:26
I am looking at tutorial where things are defined like this: planes are sprites with dynamic physics bodies plane moving is done with actions by following the path there is contact detection between bullet and plane bullet is sprite and it has physics body set to be static (which is little unusual in my opinion) Here is the link to tutorial for more information. Questions: When we use actions to move physicsBodies is there a difference how we set body's dynamic property? Because bullet is static but still there is no problem for movement. When we have situation like this, where we don't need

How to assign Keys to SKActions in Swift

谁说胖子不能爱 提交于 2019-12-04 08:50:33
I was hoping someone would be able to help me with this problem. I can't seem to find a way to assign a key to an SKAction for Sprite Kit for the removeActionWithKey method. I have also tried assinging the action to a key in a dictionary but the program didn't recognize the key assignment and thus returned a nil value. Here is what I tried to do: var textureanimation = SKAction.repeatActionForever(SKAction.animateWithTextures(_walkingframes, timePerFrame: 0.1)) var dictionary = ["animation": textureanimation] object.runAction(actionForKey("animation")) var sequence = [SKAction.moveTo(tap

EaseOut action with custom SKAction

痴心易碎 提交于 2019-12-04 07:33:19
I have the following custom SKAction working but as an EaseIn instead EaseOut. I want it to EaseOut! I have failed miserably to correct it using various easing equations found around the web. let duration = 2.0 let initialX = cameraNode.position.x let customEaseOut = SKAction.customActionWithDuration(duration, actionBlock: {node, elapsedTime in let t = Double(elapsedTime)/duration let b = Double(initialX) let c = Double(targetPoint.x) let p = t*t*t*t*t let l = b*(1-p) + c*p node.position.x = CGFloat(l) }) cameraNode.runAction(customEaseOut) Any help would be much appreciate. Thanks We can

Repeat SKAction starting position changes

那年仲夏 提交于 2019-12-04 06:34:15
问题 I've got a path and a SKShapeNode and would like to have the SKShapeNode follow the path forever (Hexagon shape). let pathHexagon:SKShapeNode = SKShapeNode() let player:SKShapeNode = SKShapeNode() pathHexagon.path = playerHexagonPath(pathHexRadius) pathHexagon.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame)) pathHexagon.strokeColor = UIColor.blackColor() pathHexagon.lineWidth = 5 addChild(pathHexagon) player.path = playerPath(playerSize) player.position = CGPoint(x:

Equivalent of SKAction scaleToX for a given duration in Unity

假装没事ソ 提交于 2019-12-04 04:41:37
问题 I am trying to scale the x axis of a sprite over a given duration in Unity. Basically I've done this before using Swift in the following way, let increaseSpriteXAction = SKAction.scaleXTo(self.size.width/(mySprite?.sprite.size.width)!, duration:0.2) mySprite!.sprite.runAction(increaseSpriteXAction) mySprite!.sprite.physicsBody = SKPhysicsBody(rectangleOfSize:mySprite!.sprite.size, center: centerPoint) but haven't even found an equivalent for scaleToX in Unity. I'll really appreciate some

checking if an SKNode is running a SKAction

非 Y 不嫁゛ 提交于 2019-12-04 04:25:42
How can I check whether a SKNode is already running an action before running an action on it? I want to be able to do something like... if (![mySprite isRunningActions]) { [mySprite runAction:action]; } If there is no built in way I'm thinking of creating a new BOOL property for holding the action state. Look at using named actions using any of the SKAction key-based methods. So you would instead run your action using the named equivalent to runAction: which is runAction:withKey: . If an action with the same key is already running, it is removed before the new one is added. Alternatively, use

Play Sound in Swift SpriteKit project?

感情迁移 提交于 2019-12-04 01:26:24
问题 When I run this code. runAction(SKAction.playSoundFileNamed("Click.mp3", waitForCompletion: false)) My app was Crashed: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Resource Click.mp3 cannot be found in the main bundle' 回答1: verify that the file exists in the project. instantiates the variables in the file first and then make a method for breeding. if the file exists in the project you should do the following: var sound = SKAction.playSoundFileNamed("sound