RenderTexture cannot read data now, so use cc. Image to do,
Directly on code: first of all to lua_binding below auto lua_cocos2dx_auto below. The CCP add lua interface:
Static int lua_cocos2dx_Image_isPointContainsAlpha (lua_State * tolua_S)
{
Cocos2d: : the Image * cobj=(cocos2d: : the Image *) tolua_tousertype (tolua_S, 1, 0);
Unsigned char * data=https://bbs.csdn.net/topics/cobj-> getData ();
If (data=NULL https://bbs.csdn.net/topics/=
{
Printf (" the data is null, ");
return 0;
}
Float y=lua_tointeger (tolua_S, 1);
Float x=lua_tointeger (tolua_S, 2);
Printf (" % f, % f ", x, y);
Int pa=4 * ((cobj - & gt; GetHeight () - 1) * y cobj - & gt; GetWidth () + x + 3);
Unsigned int ap=data (pa);
Printf (" alpha data is==% d ", ap);
If (ap & lt; 20)
{
Lua_pushboolean (tolua_S, false);
return 1;
}
The else
{
Lua_pushboolean (tolua_S, true);
return 1;
}
}
And then, in lua layer calls: local function onTouchBegan (touch, event)
The local target=event. GetCurrentTarget (event)
The local nodepos=target: getParent () : convertTouchToNodeSpace (touch)
The local box=target: getBoundingBox ()
If the cc. RectContainsPoint (box, nodepos) then
The local img=cc. Image: new ()
Img: initWithImageFile (" ship_part0. PNG ")
The local localpos=target: convertTouchToNodeSpace (touch)
The local val=img: isPointContainsAlpha (localpos. X, localpos. Y)
Print (" lua val ".. The tostring (val))
If val==true then
The local fadeOut=cc. FadeOut: create (0.2)
The local fadeIn=cc. FadeIn: create (0.2)
The local action=cc. Sequence: the create (fadeOut, fadeIn)
Sp_part0: runAction (action)
End
Return true
End
Return false
End
The local dispatcher=cc. Director: getInstance () : getEventDispatcher ()
The local listener=cc. EventListenerTouchOneByOne: create ()
Listener: registerScriptHandler (onTouchBegan, cc. Handler. EVENT_TOUCH_BEGAN)
Dispatcher: addEventListenerWithSceneGraphPriority (listener, sp_part0)
Say that finish,