Cocos2dx mask layer failed on android phone, cocos2dxandroid
1. Use CCClippingNode (OK on the simulator, not on the mobile phone) to achieve multiple cut areas
Local layer = CCLayerColor: create (ccc4 (0,110 ))
--/* Create a cropping node */
Local pClip = CCClippingNode: create ()
PClip: setInverted (true) --; // sets whether to reverse. It determines whether the circle is transparent or black.
PClip: setAlphaThreshold (0.0)
Self: addChild (pClip)
--/* Add the LayerColor layer to the cropping node */
PClip: addChild (layer)
Local stencilNode = display. newNode ()
StencilNode: setAnchorPoint (ccp (0, 0 ))
StencilNode: setPosition (ccp (0, 0 ))
--/* Draw a circular area */
Local radius = NODE_PADDING/2 + 10 --; // set the circle radius
Local nCount = 200 --; // set the number of vertices. Here we regard the circle as 200 edge.
Local angel = 2.0*3.14/nCount
Local points = CCPointArray: create (nCount)
For I = 0, nCount-1 do
Local radian = I * angel
Points: add (ccp (radius * math. cos (radian), radius * math. sin (radian )))
End
--/* Use a polygon to draw circles */
-- Create a CCPolygonShape object
Local stencil_1 = CCPolygonShape: create (points)
Stencil_1: setFill (true) -- fill
Stencil_1: setClose (true) -- close
Stencil_1: setPosition (ccp (x1, y1 ))
StencilNode: addChild (stencil_1)
-- Adds an image cut area.
Local stencil_2 = display. newSprite ("light.png ")
Stencil_1: setPosition (ccp (x2, y2 ))
StencilNode: addChild (stencil_2)
PClip: setstenpencil (stencilNode)
2. The point is, this can be used on the mobile phone.
Function game: mask ()
Local function setBlend (obj, src, dst)
Local B = ccBlendFunc: new ()
B. src = src
B. dst = dst
Obj: setBlendFunc (B)
End
-- Background
Local node = display. newNode (): zorder (10000)
Local layer = display. newColorLayer (ccc4 (0, 0, 0 ))
Node: addChild (layer)
-- Node: setContentSize (CCSize (1000,100 0 ))
Local myLayer = display. newColorLayer (ccc4 (0,175 ))
-- Create a masked Image
Local pMask
PMask = display. newSprite ("Export bun_1_1.png ")
PMask: setScaleX (1.5)
PMask: setScaleY (1.5) -- set the zoom
PMask: setAnchorPoint (ccp (0, 0 ))
PMask: setPosition (display. cx, display. cy)
-- Set the Mixed Mode
SetBlend (pMask, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA)
-- Create a clean canvas
Local pRt = CCRenderTexture: create (CONFIG_SCREEN_WIDTH, CONFIG_SCREEN_HEIGHT)
Self: addChild (pRt );
PRt: setPosition (CONFIG_SCREEN_WIDTH/2, CONFIG_SCREEN_HEIGHT/2)
-- Start drawing
PRt: begin ()
MyLayer: visit ()
-- If pData then
PMask: visit ()
-- End
PRt: endToLua ()
-- Self: addChild (myLayer)
-- Enable touch
-- Function onTouch (event, x, y)
-- EchoInfo (string. format ("# onTouch111 X = % s", x ))
-- EchoInfo (string. format ("# onTouch 111Y = % s", y ))
-- If x> display. cx-100 and x <display. cx + 100 and y> display. cy-100 and y <display. cy + 100 then
-- Node: removeFromParent ()
-- PRt: removeFromParent ()
-- End
-- Return true
-- End
-- Enable touch
-- Node: setTouchEnabled (true)
-- Node: addTouchEventListener (onTouch)
-- Node: setNodeEventEnabled (true)
-- Self: addChild (node, 1000)
End
Problems with cocos2dx android Development
If you do not know the specific situation, I can import them normally.
Ios and android are both developed in the native language. Which one is faster than cocos2dx? Because cocos2dx has various problems.
Cocos2dx is used for game development. If it is used, it is certainly not possible to use the game engine. The game uses cocos2dx in a complex way, and the engine is not needed if it is not complex.