Swift: change speed of a moveTo SKAction
You can't change the speed of an action itself, because SKAction
objects are "fire and forget" and reusable — once you pass one to a node's runAction
method, what you do to that action instance no longer affects what the node is doing to run the action.
But there are a few other options here.
Change the
speed
property of the node being animated. You can do this either directly or by running aspeedBy
orspeedTo
action. This property is a multiplier that changes how fast that node runs any and all actions attached to it, so you can set it below1.0
to slow down whatever's going on, or above1.0
to speed things up.Control the node more directly with a custom action that periodically runs a block; in that block, you can directly set the node's position, and you can check external state to determine whether to move the mode more or less per time interval.
Control the node's position directly during your scene's (or scene delegate's)
update
loop, at which point you can control the amount of movement per frame however you like.
SpriteKit increasing speed of move action
I cannot think of a way of speeding up the lines without increasing the speed on all the lines. without increasing the speed to all the lines you are going to have the problem of the shrinking gap between the lines or else you will have to transverse through all the lines on the screen and re-write their actions at the same time.
What you could do which is probably considerably easier is to create 2 larger panels that scroll through your scene top to bottom and reset when scrolls off the page at the bottom, creating a scrolling background of sorts. Then apply your bars to those panels. you now will have the effect of the bars moving down the screen. when you want to increase the speed at which the game is getting played all you have to do is increase the speed on the 2 panels.
In my demo image I've added multiple colors just to show you the breaks between the panels. but if those background colors were removed you wouldn't even realize that it was the panels moving and not the bars ;)
As an added bonus you could create the panels as a class and the bars as a class and assign the bars to the panels. when it comes time to reset the panel to the top you could just adjust the 2 inner opening points of the bars to a new gap. This way you wouldn't be creating these bars dynamically on the fly.
Changing speed of node / Swift 3.0
There are a couple of ways you can do this.
Change the duration, as this will speed it up, but I don't think this is what you're asking. I think you want to know how to speed up an SKAction....
Change the rate of execution of a SKAction via its speed property
The speed property is documented here.
You'll need to do a couple of things to make this value accessible and uniquely addressable for bubble1
Make the SKAction on bubble1 unique, so you can control it. There's two ways to to this:
- give it a unique name in its '.name' property, look up and find that
- have a reference to bubble1 and address its SKAction (a
Tell the SKAction affecting bubble1 to run faster by changing its .speed property
Or... you can be lazy and just adjust the speed value of all actions on any given node, with this: https://developer.apple.com/reference/spritekit/sknode/1483036-speed
Moving an object across the screen at a certain speed.(Sprite Kit)
I think you could revise your approach based on the calculation speed.
So, if you know your speed, you can calculate how many time a node takes to arrive to a point and change your speed to a reasonable value.
// #-#-#-#-#-#-#-#-#-#-#-#-#-#-#
//MARK: - Calculate action duration btw two points and speed
// #-#-#-#-#-#-#-#-#-#-#-#-#-#-#
func getDuration(pointA:CGPoint,pointB:CGPoint,speed:CGFloat)->NSTimeInterval {
let xDist = (pointB.x - pointA.x)
let yDist = (pointB.y - pointA.y)
let distance = sqrt((xDist * xDist) + (yDist * yDist));
let duration : NSTimeInterval = NSTimeInterval(distance/speed)
return duration
}
Suppose you have your node with a speed of 150.0
Your move will be:
let moveObject = SKAction.moveTo(endpoint, duration: getDuration(node.position,pointB:endpoint,speed:150.0))
With this approach you speed dont' change and you don't have this disagreeable slowness.
P.S. Don't forgot to change the uppercase to your properties: in swift is a bad attitude, use object instead of Object.
Swift 2: SKAction to change y position
Solved it using this code:
let moveDown = SKAction.moveToY(0, duration: 0.3)
player.runAction(moveDown)
Related Topics
Read UId from Nfc Mifare Tag iOS 13
Is There an Object Class in Swift
Programmatic Beginrefreshing() on iOS11 Has Problems with Largetitles Mode
Validate Unicode Code Point in Swift
How to Properly Map JSON Properties to Model Properties in Realm.Create
iOS - Could Not Open Obj File When Convert Mdlasset to Mdlmesh
How to Change Bordercolor When Button.Ishighlighted
Create Objects/Instances in Variables Swift
How to Apply Impulse to The Node on Touch Angle
How to Remove Items from an Array When Deselecting a Row in a UItableview
Uipickerviewdelegate Xcode 8 Swift 3
Creating Semaphore with Initial Value of 0 Make Issues with Execution
Cllocationmanager and Tvos - Requestwheninuseauthorization() Not Prompting
Should I Invalidate Timer When My Application Is Suspended or in Background
How to Move an Object Towards a Direction Without Stopping
Prevent Nscollectionview 'Lifting' an Item During Drag
Keep Getting an Error: "Uiimagepickercontroller Extension Discovery Failed with Error: (Null)"