Kobold2D  1.1
Kobold2D API Reference (iOS version) for Kobold2D developers
KKPixelMaskSprite Interface Reference

#include <KKPixelMaskSprite.h>

List of all members.

Public Member Functions

id initWithFile:alphaThreshold: (NSString *filename,[alphaThreshold] UInt8 alphaThreshold)
BOOL pixelMaskContainsPoint: (CGPoint point)
BOOL pixelMaskIntersectsNode: (CCNode *other)

Static Public Member Functions

id spriteWithFile: (NSString *filename)
id spriteWithFile:alphaThreshold: (NSString *filename,[alphaThreshold] UInt8 alphaThreshold)

Detailed Description

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.


Member Function Documentation

id KKPixelMaskSprite::initWithFile:alphaThreshold: ( NSString *  filename,
[alphaThreshold] UInt8  alphaThreshold 
) [virtual]

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.

BOOL KKPixelMaskSprite::pixelMaskContainsPoint: ( CGPoint  point) [virtual]

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.

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

BOOL KKPixelMaskSprite::pixelMaskIntersectsNode: ( CCNode *  other) [virtual]

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.

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!

id KKPixelMaskSprite::spriteWithFile: ( NSString *  filename) [static, virtual]

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

id KKPixelMaskSprite::spriteWithFile:alphaThreshold: ( NSString *  filename,
[alphaThreshold] UInt8  alphaThreshold 
) [static, virtual]

Same as initWithFile but returns an autoreleased instance.


The documentation for this interface was generated from the following file: