---
title: "customAction(withDuration:actionBlock:)"
framework: spritekit
role: symbol
role_heading: Type Method
path: "spritekit/skaction/customaction(withduration:actionblock:)"
---

# customAction(withDuration:actionBlock:)

Creates an action that executes a block over a duration.

## Declaration

```swift
class func customAction(withDuration duration: TimeInterval, actionBlock block: @escaping (SKNode, CGFloat) -> Void) -> SKAction
```

## Parameters

- `duration`: The duration of the action, in seconds.
- `block`: The block to run. The block takes the following parameters:

## Return Value

Return Value A new action object.

## Discussion

Discussion When the action executes, the block is called repeatedly until the action’s duration expires. The elapsed time is computed and passed to the block whenever the block is called. This action is not reversible; the reverse action executes the same block. The following Swift code shows how you can create a custom action to update an attribute of an SKShader attached to a sprite node. let customAction = SKAction.customAction(withDuration: 2.0) {     node, elapsedTime in          if let node = node as? SKSpriteNode {         node.setValue(SKAttributeValue(float: Float(elapsedTime)),                                        forAttribute: "a_time")     } }

## See Also

### Creating Custom Actions

- [init(named:)](spritekit/skaction/init(named:).md)
- [init(named:duration:)](spritekit/skaction/init(named:duration:).md)
- [init(named:fromURL:)](spritekit/skaction/init(named:fromurl:).md)
- [init(named:fromURL:duration:)](spritekit/skaction/init(named:fromurl:duration:).md)
- [perform(_:onTarget:)](spritekit/skaction/perform(_:ontarget:).md)
- [run(_:)](spritekit/skaction/run(_:).md)
- [run(_:queue:)](spritekit/skaction/run(_:queue:).md)
