Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2d-x画圆角矩形的Lua实现大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

-- 传入DrawNode对象,画圆角矩形 function drawNodeRoundRect(drawNode,rect,borderWidth,radius,color,fillColor) -- segments表示圆角的精细度,值越大越精细 local segments = 100 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,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,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,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,y)) end if fillColor == nil then fillColor = cc.c4f(0,0) end drawNode:drawPolygon(pPolygonPtArr,#pPolygonPtArr,fillColor,color) end

链接描述

大佬总结

以上是大佬教程为你收集整理的cocos2d-x画圆角矩形的Lua实现全部内容,希望文章能够帮你解决cocos2d-x画圆角矩形的Lua实现所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。