CCCallBlockN的替代品在Cocos2d v3.0 [英] CCCallBlockN's alternative in Cocos2d v3.0

查看:232
本文介绍了CCCallBlockN的替代品在Cocos2d v3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cocos2d 3.0的CCCallBlockN替代方法是什么?



这是我的Cocos2d 2.0代码:



< id calBlock = [CCCallBlockN actionWithBlock:^(CCNode * node){
node.position = orign;
}];

解决方案

CCCallBlockN CCCallBlockND 变量一直是多余的,因为块可以引用本地作用域中的对象:

  id someData =(某些数据创建或获取); 
CCNode * someNode =(某些节点创建或获取);
id callBlock = [CCActionCallBlock actionWithBlock:^ {
someNode.position = origin;
[someData quickDoSomething];
}];
[someNode runAction:callBlock];

您只需要一个引用 someNode 在块的外部范围内,以便在块内使用它。



通常会有所需的节点引用,因为在创建操作后,您将在所需的节点上运行操作。只有在你首先创建动作并在以后运行它们的情况下,传入的节点才有用,但我想这是一个罕见的情况,可能不是好的风格。


What's CCCallBlockN alternative for Cocos2d 3.0 ?

Here is my Cocos2d 2.0 Code:

    id calBlock = [CCCallBlockN actionWithBlock:^(CCNode *node){
        node.position         = orign;
    }];

解决方案

The CCCallBlockN and CCCallBlockND variants have always been superfluous since blocks can reference objects in the local scope:

id someData = (some data however created or obtained);
CCNode* someNode = (some node however created or obtained);
id callBlock = [CCActionCallBlock actionWithBlock:^{
    someNode.position = origin;
    [someData quickDoSomething];
}];
[someNode runAction:callBlock];

You just need to have a reference like someNode in the outer scope of the block in order to use it inside the block.

You will usually have the desired node reference because after all you're going to run the action on the desired node after creating the action. Only in cases where you create the actions first and run them later would the passed-in node be useful, but I guess that's a rare situation and probably not good style anyway.

这篇关于CCCallBlockN的替代品在Cocos2d v3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆