cocos2d-iphone – Cocos2d 2.0 – 忽略层精灵透明区域的触摸

cocos2d-iphone – Cocos2d 2.0 – 忽略层精灵透明区域的触摸,第1张

概述我有一个应用程序,我有几个图层从透明度的PNG图像创建.这些层都在屏幕上彼此相交.我需要能够忽略给层的透明区域触摸,并且当用户点击层的不透明区域时,就能够被触摸检测到…请参见图片… 我怎么做?谢谢. 这里有一个可能的解决方案. 在CCLayer上实现扩展,并提供以下方法: - (BOOL)isPixelTransparentAtLocation:(CGPoint)loc { // 我有一个应用程序,我有几个图层从透明度的PNG图像创建.这些层都在屏幕上彼此相交.我需要能够忽略给层的透明区域的触摸,并且当用户点击层的不透明区域时,就能够被触摸检测到…请参见图片…

我怎么做?谢谢.

这里有一个可能的解决方案.

在cclayer上实现扩展,并提供以下方法:

- (BOol)isPixeltransparentAtLocation:(CGPoint)loc {       //Convert the location to the node space    CGPoint location = [self convertToNodeSpace:loc];    //This is the pixel we will read and test    UInt8 pixel[4];    //Prepare a render texture to draw the receiver on,so you are able to read the required pixel and test it        CGSize screenSize = [[CCDirector sharedDirector] winSize];    CCRenderTexture* renderTexture = [[CCRenderTexture alloc] initWithWIDth:screenSize.wIDth                                                                     height:screenSize.height                                                                pixelFormat:kCCTexture2DPixelFormat_RGBA8888];    [renderTexture begin];    //Draw the layer    [self draw];        //Read the 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 the pixel's Alpha byte is transparent    return (pixel[3] == 0);}
总结

以上是内存溢出为你收集整理的cocos2d-iphone – Cocos2d 2.0 – 忽略层/精灵透明区域的触摸全部内容,希望文章能够帮你解决cocos2d-iphone – Cocos2d 2.0 – 忽略层/精灵透明区域的触摸所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1085776.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存