Mask sprites with OpenGL ES 2.0 shader in Cocos2D
Objective-C C Other
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 7 commits behind tonybeltramelli:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ShaderMask.xcodeproj
ShaderMask
src
.gitignore
LICENSE-maskShader
LICENSE_cocos2d.txt
README.md

README.md

#Cocos2D-Mask-Shader

##Mask sprite with OpenGL ES 2.0 shader in Cocos2D (Adapted from https://github.com/HarrisonJackson/Cocos2D-HJMasked-Sprite)

Getting started :

  • Copy the files of the src folder into your project;
  • Don't forget to add the .fsh files to the "Copy Bundles Resources" in "Build Phases" tab;
  • Make sure that the .fsh files are not in the "Compile Sources";

Cocos2D-Mask-Shader - preview

Usage :

		// EXAMPLES MaskNegative
        //
        // example 1
        
        CCSprite *spriteToMask = [CCSprite spriteWithFile:@"image_to_mask.jpg"];
        CCSprite *spriteMask = [CCSprite spriteWithFile:@"mask.png"];
        
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithSprite:spriteMask andMaskSprite:spriteToMask];
        [self addChild:maskedSprite];
        
        // example 2
        
        CCSprite *spriteMask = [CCSprite spriteWithFile:@"mask.png"];
        
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithSprite:spriteMask andMaskFile:@"image_to_mask.jpg"];
        [self addChild:maskedSprite];
        
        // example 3
        
        CCSprite *spriteToMask = [CCSprite spriteWithFile:@"image_to_mask.jpg"];
        
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithFile:@"mask.png" andMaskSprite:spriteToMask];
        [self addChild:maskedSprite];
        
        // example 4
        
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithFile:@"mask.png" andMaskFile:@"image_to_mask.jpg"];
        [self addChild:maskedSprite];
        
        //
        // EXAMPLES MaskPositive
        //
        // example 1
        
        CCSprite *spriteToMask = [CCSprite spriteWithFile:@"image_to_mask.jpg"];
        CCSprite *spriteMask = [CCSprite spriteWithFile:@"mask.png"];
         
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithSprite:spriteMask andMaskSprite:spriteToMask andType:TRUE];
        [self addChild:maskedSprite];
        
        // example 2
        
        CCSprite *spriteMask = [CCSprite spriteWithFile:@"mask.png"];
         
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithSprite:spriteMask andMaskFile:@"image_to_mask.jpg" andType:TRUE];
        [self addChild:maskedSprite];
        
        // example 3
        
        CCSprite *spriteToMask = [CCSprite spriteWithFile:@"image_to_mask.jpg"];
         
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithFile:@"mask.png" andMaskSprite:spriteToMask andType:TRUE];
        [self addChild:maskedSprite];
         
        // example 4
        
        TBSpriteMask *maskedSprite = [[TBSpriteMask alloc] initWithFile:@"mask.png" andMaskFile:@"image_to_mask.jpg" andType:TRUE];
        [self addChild:maskedSprite];
        
        //
        // EXAMPLES update
        //
        // example 1
        
        CCSprite *spriteMask = [CCSprite spriteWithFile:@"mask.png"];
        [maskedSprite updateWithSprite:spriteMask];
        
        // example 2
        
        [maskedSprite updateWithFile:@"mask.png"];

Have fun ! @Tbeltramelli http://twitter.com/#!/tbeltramelli/