skaction

SKAction.playSoundFileNamed not working in iOS 9

血红的双手。 提交于 2019-12-08 02:55:44
问题 I think I've got my game working almost the same as it was before iOS 9 came along... I have included the entire function, but the only thing I am having a problem with is the sound effect at the beginning of the function: func collisionHappened() { let bangSoundEffect = SKAction.playSoundFileNamed("Bang.mp3", waitForCompletion: false) runAction(bangSoundEffect) //nothing happens here let defaults = NSUserDefaults() let highscore = defaults.integerForKey("highscore") if (score > highscore){

SKAction.colorizeWithColor makes SKLabelNode disappear

眉间皱痕 提交于 2019-12-07 22:51:31
问题 I'm using SKLabelNode. I'm creating it and add it to my scene as a child and it displays with no problem, but when I try to change it's color (not fontColor) with the colorizeWithColor() method the label fades out. Here is the line with the problem: myLabel.runAction(SKAction.colorizeWithColor(SKColor.blueColor(), colorBlendFactor: 1.0, duration: duration)) I printed to the console the myLabel.color property after the completion of this action and here is what I get: Optional

SKSpriteNode : Handling Collision during SKAction

本小妞迷上赌 提交于 2019-12-07 17:00:42
问题 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:

Swift-Making an SKNode simply “move forward” on an angle

落花浮王杯 提交于 2019-12-07 15:06:26
I've already asked this question in a different way here; Swift-Setting a physics body velocity by angle but the three attempts to answer it were unfortunately not exactly what I'm looking for, although I'm grateful for what they taught me anyway. I decided that I should simply rephrase my question with an example and further explanation instead of perpetuating a discussion via comments. So here it is. Imagine I have an SKNode positioned in the centre of the screen. Let's say this is a ball, so any rotation action on it is not visible. I would need a way to have a random angle selected, and

How to loop music with SKAction?

淺唱寂寞╮ 提交于 2019-12-07 13:33:19
问题 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];

Following a CGPath with SKAction without starting from beginning of CGPath

橙三吉。 提交于 2019-12-07 10:33:09
问题 I have an SKShape node that represents an ellipse. A player is placed on the current point of a Bezier Path that is based on the ellipse's CGPath: I have two actions that the player node can perform. The player can either follow the path clockwise or counterclockwise. rotateCounterClockwiseAction = SKAction.followPath(counterClockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1) rotateClockwiseAction = SKAction.followPath(clockwisePath.CGPath, asOffset: false, orientToPath:

Swift-Setting a physics body velocity by angle

本小妞迷上赌 提交于 2019-12-07 03:13:20
I was wondering if it was at all possible to make an SKNode move forward in a particular direction, but with only one factor. I'm aware of both applying an impulse and setting the velocity of a physics body, but they're both determined by two factors; dx and dy. I also know of rotating to an angle with SKActions. But is it possible to make an object simply "move forward" once it has been set on an angle? Or set its velocity with just one factor? Thanks in advance. Sure I think what you're talking about is something like this: Now let's say you have an SKSpriteNode that is called player who

SKAction: how to generate a random delay in generation of nodes

荒凉一梦 提交于 2019-12-06 15:20:09
I use the following piece of code to generate SKNodes periodically. Is there a way to make the period of generation of these SKNodes random. Specifically, how do I make the "delayFish" in the following code an action with a random delay? [self removeActionForKey:@"fishSpawn"]; SKAction* spawnFish = [SKAction performSelector:@selector(spawnLittleFishes) onTarget:self]; SKAction* delayFish = [SKAction waitForDuration:3.0/_moving.speed]; SKAction* spawnThenDelayFish = [SKAction sequence:@[spawnFish, delayFish]]; SKAction* spawnThenDelayFishForever = [SKAction repeatActionForever

Modify a repeating task sequence while running

北慕城南 提交于 2019-12-06 12:54:31
问题 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:

EaseOut action with custom SKAction

时光怂恿深爱的人放手 提交于 2019-12-06 01:43:02
问题 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 =