5

我使用下面的cocos2d代码并工作:

CCSprite *sprite1 = [[CCSprite alloc] init];
sprite1.position = ccp(SW*0.1f, SH*0.82f);
sprite1.normalMapSpriteFrame = normalMap;
sprite1.effect = glass;
sprite1.colorRGBA = [CCColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f];

现在尝试将其移植到 Swift,但colorRGBA最后一行出现错误。帮助我获得正确的代码。

    var sprite1 = CCSprite.node() as CCSprite
    sprite1.position = ccp(SW*0.1, SH*0.82);
    sprite1.normalMapSpriteFrame = normalMap;
    sprite1.effect = glass;
    sprite1.colorRGBA =  ______ ?
4

2 回答 2

2

刚刚在 Swift 中使用 SpriteBuilder 创建了一个新项目,尝试了这个并且一切正常:

var sprite = CCSprite()    
sprite.colorRGBA = CCColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)

也许您需要查看官方文档或有关桥接头的this answer ?他们将帮助你在 Swift 中使用 Objective-C 类。

于 2015-04-17T20:07:49.903 回答
1

我没有测试这个......但你可以试试

sprite1.colorRGBA =  UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0) 
于 2015-04-17T20:18:51.597 回答