SXMaskedSprite

author:
Daniel Sperl
description:
Provides pixel level masking for any Sparrow display object.
lastupdate:
2014-04-09
compatible:
v2.1
tag:
mask
homepage:
https://github.com/Gamua/Sparrow-Extension-Masked-Sprite
download:
https://github.com/Gamua/Sparrow-Extension-Masked-Sprite/archive/master.zip

Overview

The Sparrow Extension class “SXMaskedSprite” provides pixel level masking for any Sparrow display object.

Use the class as a replacement for a normal Sprite. It contains a public property called “mask” that can be set to any display object. As each frame progresses, custom blend modes will apply the mask's alpha channel to the contents of the sprite. Both animated and static display objects are supported.

Installation

Add the class files from the src-directory to your Sparrow-powered game.

Demo-Project

The demo-directory contains a sample project. If you have configured your system for Sparrow, the project should compile and run out of the box.

Sample Code

Create the sprite class and attach any display object to it, and it will act as a mask. There is no need to add the mask to the display list; you can change its position, scale, alpha, etc. to achieve different effects.

// create masked sprite and add some children
SXMaskedSprite *sprite = [SXMaskedSprite sprite];
[sprite addChild:...];
 
// create a mask
SPImage *mask = [SPImage imageWithContentsOfFile:@"my_mask.png"];
 
// apply the mask to the sprite
sprite.mask = mask;

More information

Special thanks to Jonathan Hart — his Pixelmask Starling extension was the inspiration for this port!

Discussion

No comments so far. Feel free to edit this part of the page.

  extensions/masked_sprite.txt · Last modified: 2015/09/14 11:15 (external edit)
 
Powered by DokuWiki