Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
extensions:shalphatexture [2012/08/21 00:25]
67.181.243.216 [SHAlphaTexture]
extensions:shalphatexture [2015/09/14 11:15] (current)
Line 1: Line 1:
 +~~NOTOC~~
  
 +====== SHAlphaTexture ======
 +
 +---- dataentry extension ----
 +type          : extension
 +author_mail ​  : shilo86@gmail.com Shilo White
 +description ​  : An extension for Sparrow that allows alpha handing of texture-based objects.
 +lastupdate_dt : 2012-03-12
 +compatible ​   : v1.X
 +depends ​      : ​
 +tags          : texture, image, button, alpha, touch
 +homepage_url ​ : https://​gist.github.com/​2027039
 +download_url ​ : 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 =====
 +[[http://​shilocity.net/​sparrow/​extensions/​shalphabutton/​demos/​SHAlphaButtonDemo.zip|{{http://​f.cl.ly/​items/​2i2f3W273j2s0J0Z0d0Y/​Screen%20shot%202012-03-12%20at%2010.49.22%20PM.png}}]]
 +  * Project: [[http://​shilocity.net/​sparrow/​extensions/​shalphabutton/​demos/​SHAlphaButtonDemo.zip|Alpha Button Demo]]
 +  * Recording: [[http://​shilocity.net/​sparrow/​extensions/​shalphabutton/​recordings/​SHAlphaButtonDemo.mov|SHAlphaButtonDemo.mov]]
 +
 +===== Examples =====
 +<​code>​
 +    SHAlphaTexture *texture = [SHAlphaTexture textureWithContentsOfFile:​@"​button.png"​];​
 +    SHAlphaButton *button = [SHAlphaButton buttonWithUpState:​texture];​
 +    button.allowTouchOnAlpha = 0.5f;
 +    [self addChild:​button];​
 +</​code>​
 +
 +<​code>​
 +    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]);
 +</​code>​
 +===== Source Code =====
 +%gist(2027039)%
  extensions/shalphatexture.txt · Last modified: 2015/09/14 11:15 (external edit)
 
Powered by DokuWiki