Sprite kit SKAction repeatActionForever random wait duration - sprite-kit

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

Related

Using spritekit would like to enlarging a png without positional movement

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]]]];

Sprite is slowing as it approaches touch point

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.

SKAction followPath end to end action

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.

SKAction display single image for duration?

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.

animate the increasement of a score

SO I have a label labelscore and it increase of 1000 every time there is a collision between two images. I would like to see labelscore increase of 1000 like an animated score, a running score. How can I do this?
You can use an NSTimer to call a routine every 16.7 to 50 milliseconds. In the routine increment some value and update it to the label. Rinse and repeat until this value is equal to the score. This is the basic technique of an animation game loop.
You have the option to use a repeating timer and invalidate it when you're done with it. Or setting single-shot timers within each update routine for the next iteration. You could also use CADisplayLink as an alternative to NSTimer, which may provide smoother animation under some conditions.