Question

I have an issue with SpriteKit. I have a .png that is a drop shadow for my character that is a SKSpriteNode image. When I set the mode to SKBlendModeMultiply it treats the alpha in the image as black, making the whole image a black square.

Does anyone know how to fix this issues? It even seems to happen when you also set particles in a SKEmitterNode to SKBlendNodeMultiply as well.

Was it helpful?

Solution

The problem that you are having is that your not using the correct blend mode, if your using an image with a built in alpha (like the Apple spaceship or my UFO below) you don't need to specify a blend mode as the default value of [sprite setBlendMode:SKBlendModeAlpha]; is correct for an image with an embedded alpha.

IMAGE USED

Image used

Try removing the line [sprite setBlendMode:SKBlendModeMultiply]; in you code, or replace it with [sprite setBlendMode:SKBlendModeAlpha]; to get the correct result. Here is the code I used,

CODE USED

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        self.backgroundColor = [SKColor redColor];
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"TEST_0001"];
        //[sprite setBlendMode:SKBlendModeAlpha]; // Default value

        sprite.position = location;
        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
        [sprite runAction:[SKAction repeatActionForever:action]];
        [self addChild:sprite];
    }
}

and a screen grad from the simulator showing the comp.

SIMULATOR

Output on simulator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top