skaction

Pause an SKAction in Spritekit with Swift

依然范特西╮ 提交于 2019-11-30 13:04:35
I have the following code to move an SKSpriteNode . let moveDown = SKAction.moveBy(CGVectorMake(0, -120), duration: 1) let moveUp = SKAction.moveBy(CGVectorMake(0, +120), duration: 1) let moveSequence = SKAction.sequence([moveDown, moveUp]) square.runAction(SKAction.repeatActionForever(moveSequence)) This moves the SKSpriteNode up and down forever. Is there a way that I could pause this SKAction ? So that the SKSpriteNode will freeze in its current position, and then later when I decide, continue its movement? I only want to pause the movement of this SKSpriteNode . I do not want to pause the

SKAction move forward

家住魔仙堡 提交于 2019-11-30 09:07:12
问题 How do I get a SKNode to move forward? I've been able to get the node to move in a fixed direction using [SKAction moveByX:y:duration:] but I want it to move in a direction relative to the direction its facing. I am looking to make each node turn 45 degrees then "walk" forward 50 pixels. It seems simple enough I just am not able to find it. 回答1: This will rotate, then towards where you tap -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { for

Is it possible to end an SKAction mid-action?

若如初见. 提交于 2019-11-30 08:21:30
I have a subclass of SKSpriteNode (monsterNode). It automatically runs around the screen using vectors to follow the player. I am currently using the following action to make it run around: SKAction *actionMove = [SKAction moveTo:actualDistance duration:time]; [self runAction:actionMove completion:^ { _currentState = SVGMonsterStateIdle; }]; I am wondering if its possible to make it so the monsterNode actually STOPS running the action if it hits the boundary of the iOS device screen. I currently have SKSpriteNode boundaries on the edges of the screen, linked with a contact delegate to notify

SKAction Completion Handlers; usage in Swift

不羁的心 提交于 2019-11-30 08:10:08
问题 I'm new to Swift and SpriteKit. A lot of the samples of SpriteKit Actions are in Objective C, which I can't map to, nor get working, in Swift. If running an SKAction, and upon SKAction completion wanting to do something else, how do I get this right, in Swift? spaceMan.runAction(spaceManDeathAnimation, completion: { println("red box has faded out") }) Any ideas will be greatly appreciated. Edit: for i in 0...29 { textures.append(SKTexture(imageNamed: "spaceManDeath_\(i)")) }

Run two SKActions at once

空扰寡人 提交于 2019-11-30 05:57:43
I'm using a sequence to run a list of SKActions. What I want to do however, is run an SKAction, then run two at once, then run one in sequence. Here is my code: SKNode *ballNode = [self childNodeWithName:@"ball"]; if (ballNode != Nil){ ballNode.name = nil; SKAction *delay = [SKAction waitForDuration:3]; SKAction *scale = [SKAction scaleTo:0 duration:1]; SKAction *fadeOut = [SKAction fadeOutWithDuration:1]; SKAction *remove = [SKAction removeFromParent]; //put actions in sequence SKAction *moveSequence = [SKAction sequence:@[delay, (run scale and fadeout at the same time), remove]]; //run

Animate Path Drawing in SpriteKit

回眸只為那壹抹淺笑 提交于 2019-11-29 20:33:09
问题 I'm attempting to animate the drawing of a stroke on a path using SpriteKit . I have implemented a working solution using SKActions and a separate implementation using CABasicAnimations . The SKAction solution is not very elegant; it creates and strokes a new path on each iteration of an SKAction.repeatAction(action:count:) call with each new path slightly more complete than the previous. func start() { var i:Double = 1.0 let spinAction:SKAction = SKAction.repeatAction(SKAction.sequence([

SpriteKit SKTexture.preloadTextures high memory usage Swift

你说的曾经没有我的故事 提交于 2019-11-29 18:29:18
I have a SKTextureAtlas with about 90 PNG Images. Every Image has a resolution of 2000 x 70 pixel and has a size of ~1 KB. Now I put this images from the Atlas into an array like this: var dropBarAtlas = SKTextureAtlas(named: "DropBar") for i in 0..<dropBarAtlas.textureNames.count{ var textuteName = NSString(format: "DropBar%i", i) var texture = dropBarAtlas.textureNamed(textuteName) dropFrames.addObject(texture) } Then I preload the array with the textures in didMoveToView: SKTexture.preloadTextures(dropFrames, withCompletionHandler: { () -> Void in}) To play the animation with 30 fps I use

How to interrupt a SpriteKit sequence of actions and resume as if there was no interruption

纵然是瞬间 提交于 2019-11-29 13:51:57
I would like to interrupt the sequence below for 2 seconds and resume to where it would have been if it wasn't interrupted in the first place. For example, from the code below, if I were interrupt the sequence for 2 seconds by making the sprite visible from 1.5 - 3.5 seconds into the sequence (meaning that 1 second the hideInterval action plus the showSprite action, and 0.5 seconds of the showInterval action would be missed) the interruption would end at 2.5 seconds remaining for the showInterval action. How can I get the sprite to run an action on the remaining 2.5 seconds and continue with

SKAction move forward

五迷三道 提交于 2019-11-29 12:07:16
How do I get a SKNode to move forward? I've been able to get the node to move in a fixed direction using [SKAction moveByX:y:duration:] but I want it to move in a direction relative to the direction its facing. I am looking to make each node turn 45 degrees then "walk" forward 50 pixels. It seems simple enough I just am not able to find it. This will rotate, then towards where you tap -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { for (UITouch *touch in touches) { CGPoint location = [touch locationInNode:self]; CGPoint diff = CGPointMake

Is it possible to end an SKAction mid-action?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 11:06:21
问题 I have a subclass of SKSpriteNode (monsterNode). It automatically runs around the screen using vectors to follow the player. I am currently using the following action to make it run around: SKAction *actionMove = [SKAction moveTo:actualDistance duration:time]; [self runAction:actionMove completion:^ { _currentState = SVGMonsterStateIdle; }]; I am wondering if its possible to make it so the monsterNode actually STOPS running the action if it hits the boundary of the iOS device screen. I