SKAction *ghostAnimationAction =
[SKAction animateWithTextures:ghostFrames timePerFrame:0.1];
SKAction *ghostDelayAction =
[SKAction animateWithTextures:#[[SKTexture textureWithImageNamed:#"Ghost_"]]
timePerFrame:1.0];
SKAction *ghostAnimationSequence =
[SKAction sequence:#[ghostAnimationAction, ghostDelayAction]];
SKAction *repeatGhostAnimationSequence =
[SKAction repeatActionForever:ghostAnimationSequence];
I have an animated sequence of frames which is made up of an NSMutableArray of SKTexture objects. Once that sequence has played I want to fold on a still frame for a second before repeating everything. The code above works, but the only way I can find to specify holding on a frame for a duration is to use animateWithTextures:timePerFrame: and supply a single texture array. Is there another way to get an SKAction to display a single image for a duration that I am missing.
You could create a new SKAction that encloses both of these two actions. See the Sprite Kit Programming Guide section called 'Creating Actions That Run Other Actions' here Adding Actions To Nodes
Take a look at the SKAction member waitForDuration: too, you may be able to avoid passing in the single texture that way. Have the first SKAction run your animation, then have the second SKAction waitForDuration. Then your enclosing SKAction runs through these two actions forever or as long as needed.
Related
Is there a way to enlarge a sprite node without moving the position?
I would like to animate a node to 'swell up' to a six * 6, then bring it back down to normal size in an animation loop?
I have it hard coded in a state block, where i do not move the image, but simply change the size of the sprite to simulate blowing up, then reducing the size back to normal - like when a creature was being pumped up in dig-dug....
But i was hoping there was a way to accomplish this by using something like moveTo and the animateWithTextures routine for movement.
is easy to do with the method scaleTo:duration: of SKAction
for example:
SKAction *big = [SKAction scaleTo:3 duration:0.5];
SKAction *small = [SKAction scaleTo:1 duration:0.5];
[node runAction:
[SKAction repeatActionForever:
[SKAction sequence:#[big, small]]]];
I am using SpriteKit, and my sprite is slowing as it approaches the touched point.
I would like the sprite to remain at a fixed speed as it moved from initial point to the touched point on the screen.
Currently, i have the duration set to 3.0
In the touchesEnded event, i gather the new point of the touch and save the value to a property.
In the scene update event, i perform a
float realMoveDuration = 3.0;
SKAction *actionMove = [SKAction moveTo:self.newPoint duration:realMoveDuration];
[self.player runAction:[SKAction sequence:#[actionMove]]];
So when the player sprite starts getting closer to the touch point, the movement slows down, and gradually reaches the touch point.
This is not the action I am looking for, i would like the player sprite to continue at a constant rate of travel to the touched point.
You should just run your SKAction in the touchesEnded event.
If you have that code in the update event, it's starting a new SKAction 60 times per second. You only ever need to run a new SKAction when there is a change in destination.
If there is a change in destination before you reach the original destination, you should remove the action from that node and then add a new one.
Also, not certain about the specifics of what you are doing, but how quickly an object moves is based on the distance and the time you have specified for it to get there. So if you want a node to move at a consistent speed, regardless of distance, you need to make a calculation to determine the right duration to set for your SKAction.
For example if speed represents pixels/units per second you might do this to calculate your duration :
duration = distance / speed;
If you are using an SKAction to move the sprite, use the timingMode property. The default is SKActionTimingLinear. So if you haven't changed it, the node should move at a constant speed.
Here's a link to the available Action Timing Modes.
Using SpriteKit, I have created a sprite, and would like to display the sprite, pause for a second, then begin the animation using a new sprite.
Currently, I am using
self.neko = [SKSpriteNode spriteNodeWithImageNamed:#"Awake.ico"];
[self addChild:self.neko];
sleep(2);
[self.neko removeFromParent];
Based on the code provided, you would think the sprite would be drawn, then the thread would sleep for a couple of seconds, and then remove the sprite from the parent.... but the sprite is not being shown.
If I remove the removeFromParent line, the sprite will remain on the screen.
So the question is this, am i doing it correctly?
Is there a way to force the sprite to be updated on the scene before the sleep timer is executed?
You could use an SKAction like this to display the sprite for two seconds and then remove it:
[self.neko runAction:
[SKAction sequence:#[
[SKAction waitForDuration:2.0],
[SKAction removeFromParent]
]]
];
I'm trying to use SKAction followPath with a given path, I noticed that the two methods available both take a duration.
[SKAction followPath:<#(CGPathRef)#> asOffset:<#(BOOL)#> orientToPath:<#(BOOL)#> duration:<#(NSTimeInterval)#>]
[SKAction followPath:<#(CGPathRef)#> duration:<#(NSTimeInterval)#>]
How can I get the action to stop only when it has reached the last point on the path?
Both actions stop at the last point. Duration is how long it takes the node to get to the last path point.
Thank you for helping first.
The SKAction sequence looks like this:
SKAction *seq = [SKAction sequence:#[wait, throwAnim, run]];
SKAction *req = [SKAction repeatActionForever:seq];
Is there any way to make the wait a random duration, or can be controlled during the forever repeat?
You can use waitForDuration:withRange:
Duration parameter represents average wait time, and range represents variation.
Each time the action is executed, the action computes a new random
value for the duration. The duration may vary in either direction by
up to half of the value of the durationRange parameter.
For example if you set duration to 5.0 and range to 2.0 you will get wait times between 4.0 and 6.0