【问题标题】:Converting Cocos2d code to ARC issues将 Cocos2d 代码转换为 ARC 问题
【发布时间】:2013-10-27 19:08:44
【问题描述】:

我正在尝试为项目启用 ARC,但在为 ARC 选择文件时遇到了一些问题。

在 Ball 类中,如下一行,

ballBody->SetUserData(self);

给出错误,

Cannot initialize a parameter of type 'void *' with an Ivalue of type 'Ball *const__strong'

在 Enemy.mm 类中,以下行,

enemyBody->SetUserData(enemySprite);

给出错误,

Cannot initialize a parameter of type 'void *' with an Ivalue of type 'CCPhysicsSprite*__strong'

在 Enemy.h 中,我将上述内容定义为:

b2Body* enemyBody;
CCPhysicsSprite* enemySprite; (in Enemy.m)

我该如何解决这些问题?

【问题讨论】:

    标签: cocos2d-iphone automatic-ref-counting box2d-iphone


    【解决方案1】:

    桥接:

    ballBody->SetUserData((__bridge void*)self);
    enemyBody->SetUserData((__bridge void*)enemySprite);
    

    反之:

    CCPhysicsSprite* enemySprite = (__bridge CCPhysicsSprite*)enemyBody->GetUserData();
    

    【讨论】:

      最近更新 更多