Cocos2d 2.0 - Ignoring touches to transparent areas of layers/sprites -
i have app have several layers created png images transparency. these layers on screen on each other. need able ignore touches given transparent areas of layers , able detect touches, when user taps on non-transparent area of layer... see pic...

how do that? thanks.
here have possible solution.
implement extension on cclayer , provide method:
- (bool)ispixeltransparentatlocation:(cgpoint)loc { //convert location node space cgpoint location = [self converttonodespace:loc]; //this pixel read , test uint8 pixel[4]; //prepare render texture draw receiver on, able read required pixel , test cgsize screensize = [[ccdirector shareddirector] winsize]; ccrendertexture* rendertexture = [[ccrendertexture alloc] initwithwidth:screensize.width height:screensize.height pixelformat:kcctexture2dpixelformat_rgba8888]; [rendertexture begin]; //draw layer [self draw]; //read pixel glreadpixels((glint)location.x,(glint)location.y, khittest_width, khittest_height, gl_rgba, gl_unsigned_byte, pixel); //cleanup [rendertexture end]; [rendertexture release]; //test if pixel's alpha byte transparent return (pixel[3] == 0); }
Comments
Post a Comment