Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Version of Cocos2d Code : sprite1.colorRGBA

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 =  ______ ?
like image 654
iPhoneProcessor Avatar asked Oct 20 '22 14:10

iPhoneProcessor


2 Answers

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.

like image 105
Vlad Avatar answered Nov 04 '22 00:11

Vlad


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

sprite1.colorRGBA =  UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0) 
like image 23
stepheaw Avatar answered Nov 04 '22 02:11

stepheaw