COCOS2DX mask layer on Android phone failed

Source: Internet
Author: User

1.CCClippingNode use (OK on the simulator, not on the phone), achieve multiple clipping areas

Local Layer=cclayercolor:create (CCC4 (0,0,0,110))
--/* Creating a clipping node */
Local pclip=ccclippingnode:create ()
Pclip:setinverted (True) if the--;//setting is reversed, it will determine whether the drawn circle is transparent or black.
Pclip:setalphathreshold (0.0)
Self:addchild (Pclip)
--/* Note Add the Layercolor layer to the clipping 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 radius of the circle
Local ncount=200--;//Sets the number of vertices, where we consider a circle as a 200-side
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

--/* the circle by drawing a polygon */

--Create a Ccpolygonshape object
Local Stencil_1 = ccpolygonshape:create (points)
Stencil_1:setfill (True)--fill
Stencil_1:setclose (True)--closed
Stencil_1:setposition (CCP (x1, y1))
Stencilnode:addchild (Stencil_1)

--Increase the clipping area of a picture

Local stencil_2= display.newsprite ("Light.png")

Stencil_1:setposition (CCP (x2, y2))

Stencilnode:addchild (stencil_2)

Pclip:setstencil (Stencilnode)


2. The point is, this can be used on the 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,0))
Node:addchild (layer)
--node:setcontentsize (ccsize (1000, 1000))
Local Mylayer = Display.newcolorlayer (CCC4 (0,0,0,175))
--Create a mask picture
Local Pmask
Pmask = Display.newsprite ("#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 Blending mode
Setblend (Pmask, Gl_zero, Gl_one_minus_src_alpha)


--Create a clean artboard
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 + and y > display.cy-100 and y < display.cy + Then
--Node:removefromparent ()
--Prt:removefromparent ()
--end
--return true
--End
--Open touch
--node:settouchenabled (True)
--node:addtoucheventlistener (OnTouch)
--node:setnodeeventenabled (True)
--self:addchild (node,1000)
End




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.