CCActionCallBlock Class Reference

Inherits from CCActionInstant : CCActionFiniteTime : CCAction : NSObject
Conforms to NSCopying
Declared in CCActionInstant.h

Overview

This action executes a code block. The block takes no parameters and returns nothing.

Passing Parameters

Blocks can access all variables in scope, both variables local to the method as well as instance variables. Local variables require to be declared with the __block keyword if the block needs to modify the variable.

Running a block is often preferable to running a selector because the CCActionCallFunc selector can not accept parameters.

Memory Management

To avoid potential memory management issues it is recommended to use a weak self reference inside the block. If you are knowledgeable about memory management with ARC and blocks you can omit the weakSelf reference at your discretion.

Code Example

Example block that reads and modifies a variable in scope and rotates a node to illustrate the code syntax:

__weak typeof(self) weakSelf = self;
__block BOOL blockDidRun = NO;

id callBlock = [CCActionCallBlock actionWithBlock:^{
    if (blockDidRun == NO) {
        blockDidRun = YES;
        weakSelf.rotation += 90;
    }
}];

[self runAction:callBlock];

Creating a Run Block Action

+ actionWithBlock:

Creates the action with the specified block, to be used as a callback. The block will be copied.

+ (id)actionWithBlock:(void ( ^ ) ( ))block

Parameters

block

Block to run. Block takes no parameters, returns nothing.

Return Value

The call block action.

Declared In

CCActionInstant.h

– initWithBlock:

Initializes the action with the specified block, to be used as a callback. The block will be copied.

- (id)initWithBlock:(void ( ^ ) ( ))block

Parameters

block

Block to run. Block takes no parameters, returns nothing.

Return Value

An initialized call block action.

Declared In

CCActionInstant.h