问题
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