Get the alpha value at the touched point on a sprite in Cocos2D

只谈情不闲聊 提交于 2019-12-25 01:25:09

问题


I am doing an application where I need to get the alpha value at the touched position on a sprite. Thanks in Advance


回答1:


I use this code to retrieve the alpha value:

GLubyte pColor[4];
CGPoint newpoint = (...your screen point in GL coordinates);
glReadPixels(newpoint.x,newpoint.y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,&pColor[3]);

pColor[3] then contains your alpha value.

You probably will have to combine this with code to check whether your position is inside the sprite's bounding box. Make sure you get the right coordinates.




回答2:


Probably it what you need sprite.alpha.



来源:https://stackoverflow.com/questions/4364061/get-the-alpha-value-at-the-touched-point-on-a-sprite-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!