skaction

Sound resource can not be loaded Swift SKAction

时间秒杀一切 提交于 2019-12-10 14:49:34
问题 I have an app that plays a sound file every time the screen is touched. For some reason, the app will crash every once in a while with the following error: reason: 'Resource tick.mp3 can not be loaded' In case you need it, here is how I play the file each time the screen is tapped: runAction(SKAction.playSoundFileNamed("tick.mp3", waitForCompletion: false)) This does not happen very often, maybe 1 in 10 runs of the app. Most of the time everything works as expected. I wish I knew what I am

Spawn nodes at random times combing waitForDuration:withRange and runBlock: in an SKAction sequence

只愿长相守 提交于 2019-12-10 10:29:28
问题 I am making a game with SpriteKit where I have nodes spawning at the top of the screen and falling. However, I want these nodes to spawn at a random time interval between 0.1 and 3 seconds. For example, the first node spawns in 1.3 seconds, the next in 1.8, then 2.5, then 0.8, and so forth forever. I'm not sure how to utilize the waitForDuration function to do this. The code that I currently have is: let wait = SKAction.waitForDuration(3, withRange: 2) let spawn = SKAction.runBlock { addTears

Swift: change speed of a moveTo SKAction

青春壹個敷衍的年華 提交于 2019-12-08 18:50:39
I have a simple sprite movement that I am triggering with the following line: actionMove = SKAction.moveTo(CGPoint(x: size.width + CGFloat(KUGELWIDTH / 2), y: yPos), duration: NSTimeInterval(actualDuration)) And then i call runAction in the following manner: let actionMoveDone = SKAction.removeFromParent() kugel.runAction(SKAction.sequence([actionMove, actionMoveDone])) What i am confused about, is changing the speed (duration) of the SKAction in the middle of while it is in the middle of running. This may be impossible, in which case, is there another method to invoke to move a sprite around

Does adding new action for the scene remove automatically the one before in SpriteKit?

本小妞迷上赌 提交于 2019-12-08 13:14:31
I want to know if I made a sequence action and while this sequence is running a new action added to the scene , Does the new action stop the sequence ? If yes , how i can make both of them working if the new action is added in swift ? The only time a new action will interfere with any running actions is if both actions share the same key. If you do not assign a key, then every time you add an action, it gets added to the action pool and will run concurrently. If you just give it a try, I'm sure you'll find the answer yourself. But anyway, I tried it for you: node.run(SKAction.sequence(

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

半城伤御伤魂 提交于 2019-12-08 08:16:49
问题 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,

Randomizing SKActions

我与影子孤独终老i 提交于 2019-12-08 06:32:06
问题 I'm trying to move a Sprite over the screen from left to right. The sprite should start at a random y position on the right side offscreen. With a repeatActionForever and an integer with a random Y number i want the sprite to repeat the action starting from different y Positions. Any ideas on how to achieve this besides putting the random int in an update method? Is it anyhow achieveable through actions? I use this method on the Sprite: int randomY = (arc4random()%121; SKAction *pos =

Swift: change speed of a moveTo SKAction

China☆狼群 提交于 2019-12-08 05:34:14
问题 I have a simple sprite movement that I am triggering with the following line: actionMove = SKAction.moveTo(CGPoint(x: size.width + CGFloat(KUGELWIDTH / 2), y: yPos), duration: NSTimeInterval(actualDuration)) And then i call runAction in the following manner: let actionMoveDone = SKAction.removeFromParent() kugel.runAction(SKAction.sequence([actionMove, actionMoveDone])) What i am confused about, is changing the speed (duration) of the SKAction in the middle of while it is in the middle of

Swift-Setting a physics body velocity by angle

吃可爱长大的小学妹 提交于 2019-12-08 05:06:33
问题 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. 回答1: Sure I think what you

Does adding new action for the scene remove automatically the one before in SpriteKit?

孤街浪徒 提交于 2019-12-08 04:09:22
问题 I want to know if I made a sequence action and while this sequence is running a new action added to the scene , Does the new action stop the sequence ? If yes , how i can make both of them working if the new action is added in swift ? 回答1: The only time a new action will interfere with any running actions is if both actions share the same key. If you do not assign a key, then every time you add an action, it gets added to the action pool and will run concurrently. 回答2: If you just give it a

Touch Sprite, make it jump up then fall down again(repeat as many times as spritenode is tapped.)

北战南征 提交于 2019-12-08 03:15:04
问题 I created a project where I have a ball and when the view loads, it falls down, which is good. I'm trying to get the ball to jump back up and fall down again when the Spritenode is tapped. --This Question was edited-- Originally, I was able to get it to work when sprite.userInteractionEnabled = false . I had to turn this statement true in order to get the score to change. Now I can't get the balls to fall and be tapped to jump. When I turn ball.physicsBody?.dynamic = true , the balls will