• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

cocos2dx-lua圆角矩形圆角图片drawNode

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

使用的官方类是:drawNode

函数是:drawNode:drawPolygon()

C++函数的参数说明:

//画多边形,verts为点集,count为点数,fillColor为填充颜色,borderWidth为边缘线宽,borderColor为边缘线颜色

void drawPolygon(Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);

lua用table作为点集

 

代码如下:

 drawNodeRoundRect(drawNode, rect, borderWidth, radius, color, fillColor)
        -- segments表示圆角的精细度,值越大越精细
        local segments = 100
        --local segments = 4
        local origin = cc.p(rect.x, rect.y)
        local destination = cc.p(rect.x + rect.width, rect.y - rect.height)
        local points = { }

        -- 算出1/4圆
        local coef = math.pi / 2 / segments
        local vertices = { }

        for i = 0, segments do
            local rads =(segments - i) * coef
            local x = radius * math.sin(rads)
            local y = radius * math.cos(rads)

            table.insert(vertices, cc.p(x, y))
        end

        local tagCenter = cc.p(0, 0)
        local minX = math.min(origin.x, destination.x)
        local maxX = math.max(origin.x, destination.x)
        local minY = math.min(origin.y, destination.y)
        local maxY = math.max(origin.y, destination.y)
        local dwPolygonPtMax =(segments + 1) * 4
        local pPolygonPtArr = { }

        -- 左上角
        tagCenter.x = minX + radius;
        tagCenter.y = maxY - radius;

        for i = 0, segments do
            local x = tagCenter.x - vertices[i + 1].x
            local y = tagCenter.y + vertices[i + 1].y

            table.insert(pPolygonPtArr, cc.p(x, y))
        end

        -- 右上角
        tagCenter.x = maxX - radius;
        tagCenter.y = maxY - radius;

        for i = 0, segments do
            local x = tagCenter.x + vertices[#vertices - i].x
            local y = tagCenter.y + vertices[#vertices - i].y

            table.insert(pPolygonPtArr, cc.p(x, y))
        end

        -- 右下角
        tagCenter.x = maxX - radius;
        tagCenter.y = minY + radius;

        for i = 0, segments do
            local x = tagCenter.x + vertices[i + 1].x
            local y = tagCenter.y - vertices[i + 1].y

            table.insert(pPolygonPtArr, cc.p(x, y))
        end

        -- 左下角
        tagCenter.x = minX + radius;
        tagCenter.y = minY + radius;

        for i = 0, segments do
            local x = tagCenter.x - vertices[#vertices - i].x
            local y = tagCenter.y - vertices[#vertices - i].y

            table.insert(pPolygonPtArr, cc.p(x, y))
        end

        if fillColor == nil then
            fillColor = cc.c4f(1, 1, 1, 1)
        end

        drawNode:drawPolygon(pPolygonPtArr, #pPolygonPtArr, fillColor, borderWidth, color)
    end


    --创建DrawNode
local imagePath = "res/test.png" head = cc.DrawNode:createWithFilename(imagePath) head:setAnchorPoint(cc.p(0.5, 0.5)) head:setPosition(cc.p(156+700-190, 134+170+120)) scene:addChild(head,9999) --配置参数 local TestRect = {} TestRect.x = 0 TestRect.width = 535 TestRect.y=0 TestRect.height = 235 local TestBorderWidth = 0 local TestColor = cc.c4f(1,1,1,1) local Testradius = 20 head:clear() drawNodeRoundRect(head,TestRect,TestBorderWidth,Testradius,TestColor,TestColor)

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap