SHAlphaTexture

type:
extension
author:
Shilo White
description:
An extension for Sparrow that allows alpha handing of texture-based objects.
lastupdate:
2012-03-12
compatible:
v1.X
tag:
texture, image, button, alpha, touch
homepage:
https://gist.github.com/2027039
download:
https://gist.github.com/gists/2027039/download

Description

This extension enables the use of these 5 classes:

  • SHAlphaButton
  • SHAlphaImage
  • SHAlphaTexture
  • SHAlphaSubTexture (abstract)
  • SHGLAlphaTexture (abstract)

The purpose of this extension is to allow Sparrow to be aware of when a touch inside a button or image contains a valid alpha value.

With the use of the property “allowTouchOnAlpha” and the method “alphaOfPixelWithX:y:”, you will be able to interact with the alpha value of pixels inside the given texture.

Note: These classes will store the alpha data and perform an extra check upon hitTest, so it should only be used when needing more accurate hit tests with textures containing transparent pixels.

Warning: The hit testing accuracy is not perfect and also depends on image quality. Use at own risk.

Sample

Examples

    SHAlphaTexture *texture = [SHAlphaTexture textureWithContentsOfFile:@"button.png"];
    SHAlphaButton *button = [SHAlphaButton buttonWithUpState:texture];
    button.allowTouchOnAlpha = 0.5f;
    [self addChild:button];
    SHAlphaImage *image = [SHAlphaImage imageWithContentsOfFile:@"image.png"];
    image.allowTouchOnAlpha = 1.0f;
    [self addChild:image];
    NSLog(@"alpha value of top-left pixel = %f", [image alphaOfPixelWithX:0 y:0]);

Source Code

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