Inherits from CCSprite : CCNodeRGBA : CCNode : NSObject
Declared in KKPixelMaskSprite.h

Overview

KKPixelMaskSprite is a CCSprite that has a pixelMask for pixel-perfect collision detection.

Notable behavior of this class: – Each instance creates its own pixelMask, even though the same texture may already be loaded. – Can only compare HD vs HD or SD vs SD images, but not HD vs SD images. – Can not be created from spriteframe or spriteframe name. .

These may be fixed at a later time given enough interest.

Tasks

  •   pixelMask property
  •   pixelMaskWidth property
  •   pixelMaskHeight property
  •   pixelMaskSize property
  • – initWithFile:alphaThreshold:

    Initializer with filename and alphaThreshold (range 0-255). The alpha value of a pixel must be > alphaThreshold to be added as a collision bit to the pixelMask. Ie alphaThreshold = 255 ensures that only fully opaque pixels are colliding, and alphaThreshold == 0 ensures that all but completely transparent pixels are considered for collision bits.

  • + spriteWithFile:

    Same as initWithFile but returns an autoreleased instance with alphaThreshold defaulting to 255 (only fully opaque pixels are collision bits).

  • + spriteWithFile:alphaThreshold:

    Same as initWithFile but returns an autoreleased instance.

  • – pixelMaskContainsPoint:

    Returns YES if the given point (in world/screen coordinates) is on a collision bit that is set to YES in the pixelMask. Returns NO if the point in the pixelMask is not colliding, or if the point lies outside the bounds of the pixelMask.

  • – pixelMaskIntersectsNode:

    Returns YES if the given node intersection contains a pixelMask collision bit. If the node is a non-KKPixelMaskSprite node then the intersection rectangle (if any) will be tested for containing any collision bits and return YES if the other node’s boundingBox intersection contains a pixelMask collision. Returns NO if the nodes aren’t colliding or if there is no pixelMask collision.

Properties

pixelMask

pixelMaskHeight

pixelMaskSize

pixelMaskWidth

Class Methods

spriteWithFile:

Same as initWithFile but returns an autoreleased instance with alphaThreshold defaulting to 255 (only fully opaque pixels are collision bits).

+ (id)spriteWithFile:(NSString *)filename

Declared In

KKPixelMaskSprite.h

spriteWithFile:alphaThreshold:

Same as initWithFile but returns an autoreleased instance.

+ (id)spriteWithFile:(NSString *)filename alphaThreshold:(UInt8)alphaThreshold

Declared In

KKPixelMaskSprite.h

Instance Methods

initWithFile:alphaThreshold:

Initializer with filename and alphaThreshold (range 0-255). The alpha value of a pixel must be > alphaThreshold to be added as a collision bit to the pixelMask. Ie alphaThreshold = 255 ensures that only fully opaque pixels are colliding, and alphaThreshold == 0 ensures that all but completely transparent pixels are considered for collision bits.

- (id)initWithFile:(NSString *)filename alphaThreshold:(UInt8)alphaThreshold

Declared In

KKPixelMaskSprite.h

pixelMaskContainsPoint:

Returns YES if the given point (in world/screen coordinates) is on a collision bit that is set to YES in the pixelMask. Returns NO if the point in the pixelMask is not colliding, or if the point lies outside the bounds of the pixelMask.

- (BOOL)pixelMaskContainsPoint:(CGPoint)point

Discussion

Note: The KKPixelMaskSprite may be rotated and/or scaled.

Declared In

KKPixelMaskSprite.h

pixelMaskIntersectsNode:

Returns YES if the given node intersection contains a pixelMask collision bit. If the node is a non-KKPixelMaskSprite node then the intersection rectangle (if any) will be tested for containing any collision bits and return YES if the other node’s boundingBox intersection contains a pixelMask collision. Returns NO if the nodes aren’t colliding or if there is no pixelMask collision.

- (BOOL)pixelMaskIntersectsNode:(CCNode *)other

Discussion

If the other node is of class KKPixelMaskSprite an accurate pixelMask vs. pixelMask comparison is performed. If the intersection of the two nodes contains a pixelMask collision bit set at the same coordinates, then the two nodes are colliding and YES is returned.

Note: both nodes may NOT be rotated or scaled. This test only works with non-rotated, non-scaled nodes!

Declared In

KKPixelMaskSprite.h