5

I used below cocos2d code and worked:

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];

Now tried to port it to Swift, but getting error for colorRGBA last line. Help me to get right code.

    var sprite1 = CCSprite.node() as CCSprite
    sprite1.position = ccp(SW*0.1, SH*0.82);
    sprite1.normalMapSpriteFrame = normalMap;
    sprite1.effect = glass;
    sprite1.colorRGBA =  ______ ?
Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
iPhoneProcessor
  • 4,980
  • 6
  • 27
  • 49

2 Answers2

2

Just created a new project with SpriteBuilder in Swift, tried this and all worked:

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

Maybe you need to look at official documentation or this answer about bridging headers? They will help you to use Objective-C classes in Swift.

Community
  • 1
  • 1
Vlad
  • 7,199
  • 2
  • 25
  • 32
1

I did not test this...but you can try

sprite1.colorRGBA =  UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0) 
stepheaw
  • 1,683
  • 3
  • 22
  • 35