skaction

Animate an SKSpriteNode with textures that have a size different from the original

牧云@^-^@ 提交于 2019-12-19 10:56:11
问题 I want to animate an SKSpriteNode using textures from an SKTextureAtlas, using SKAction.animateWithTextures(textures,timePerFrame,resize,restore) . However, the textures in the atlas have a size that is slightly larger than the original texture (it's basically a character moving). When the action is run, the textures are either compressed to fit the original size of the sprite, or recentered when I set resize to false , which changes the position of the character. What I want, though, is for

Pause an SKAction in Spritekit with Swift

只谈情不闲聊 提交于 2019-12-18 15:55:26
问题 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,

How to move enemy towards a moving player?

亡梦爱人 提交于 2019-12-17 02:37:58
问题 I am creating a simple sprite kit game that will position a player on the left side of the screen, while enemies approach from the right. Since the player can be moved up and down, I want the enemies to "smartly" adjust their path towards the player. I tried removing and re-adding the SKAction sequence whenever the player moves, but the below code causes the enemies to not show at all, probably because its just adding and removing each action on every frame update, so they never have a chance

SKAction Perform Selector syntax error

ⅰ亾dé卋堺 提交于 2019-12-13 06:58:11
问题 Using a SKAction sequence I am trying to add a delay and then call a method with two parameters, however I keep getting the following (new to obj c so could be something simple): // code SKAction *fireAction = [SKAction sequence:@[[SKAction waitForDuration:1.5 withRange:0], [SKAction performSelector:@selector(addExplosion:firstBody.node.position andTheName: @"whiteExplosion") onTarget:self]]]; // error Expected ':' Method declaration -(void) addExplosion : (CGPoint) position andTheName :

Cannot convert value of type 'NSMutableArray' to expected argument type '[SKAction]'

佐手、 提交于 2019-12-13 01:37:57
问题 I checked my old game (made in SpriteKit) and I want to update it in Swift 2.0. When I tried to fix it, Xcode found an errors. Error is: Cannot convert value of type 'NSMutableArray' to expected argument type '[SKAction]' In code: torpedo.runAction(SKAction.sequence(actionArray)) Function: override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { self.runAction(SKAction.playSoundFileNamed("torpedo.mp3", waitForCompletion: false)) var touch:UITouch = touches.anyObject() as

SKEase action, how to use Float changing Action Setter Block?

浪子不回头ぞ 提交于 2019-12-12 19:07:08
问题 In the following use case, I'm trying to animate the lineWidth of an SKShapeNode . SKEase is part of the wonderful SpriteKitEasing github repo from Craig Grummitt. One of its facilities is a Float changing ease action that appears to change the value of a float over time. However I can't figure out how to use it. Xcode gives the following suggestions when typing it in: let lineWeight = SKEase.createFloatTween(<start: CGFloat, end: CGFloat, time: TimeInterval, easingFunction: AHEasingFunction,

iOS7 SpriteKit how to wait for an animation to complete before resuming method execution?

混江龙づ霸主 提交于 2019-12-12 18:17:57
问题 Is there a way to make a method wait for a SpriteKit action initiated within the method to complete before continuing code execution? Here's what I have so far, but it just hangs at the wait loop. __block BOOL wait = YES; SKAction* move = [SKAction moveTo:destination duration:realMoveDuration]; SKAction* sequence = [SKAction sequence:@[[SKAction waitForDuration:0.07],move,[SKAction waitForDuration:0.07] ]]; [spellEffect runAction:sequence completion:^{ [spellEffect removeFromParent]; wait =

SkSpriteNode.Run Action don't Works some times

北战南征 提交于 2019-12-12 10:21:42
问题 this is my first SpriteKit game and I didn't had any problems with run action before so I tried but can't figure anything out, only thing I figure out is all code is fine but just run action don't execute some times and didn't seen any king of behaviour in that pattern. I I'm making 4 player board game and all 4 players have 4 pieces. the problem is with returning to home when ever any player piece kills other player's piece that piece comes back to home before it was working fine but I added

Function to run a wait action at decreasing intervals indefinitely

社会主义新天地 提交于 2019-12-12 01:25:47
问题 I have code which runs a wait action for a duration of columnTime and then runs a block of code. This results in the block running once, then wait time, then block, then wait time, etc. func startSpawning(){ print(columnTime) let wait = SKAction.waitForDuration(columnTime) let block = SKAction.runBlock({[unowned self] in self.spawnObstacle()}) let sequence = SKAction.sequence([wait, block]) runAction(SKAction.repeatActionForever(sequence), withKey: "spawning") } //startSpawning I want the

What is a selector in SKAction: perform(_:onTarget:)

孤者浪人 提交于 2019-12-10 17:42:42
问题 The docs say: Declaration: class func perform(_ selector: Selector, onTarget target: Any) -> SKAction selector The selector of the method to call. I am uncertain what a selector of a method is. Hence the question. It seems like it would be the name of the method/function, but creates (in me) uncertainty because it's never described as being this, so I kind of think it might be something else, something more profound, perhaps. I'm presupposing perform(_:onTarget) is a way for a part of code to