使用的官方类是: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作为点集

代码如下:

function drawNodeRoundRect(drawNode, rect, borderWidth, radius, color, fillColor)
-- segments表示圆角的精细度,值越大越精细
local segments =
--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 / / segments
local vertices = { } for i = , 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(, )
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 + ) *
local pPolygonPtArr = { } -- 左上角
tagCenter.x = minX + radius;
tagCenter.y = maxY - radius; for i = , segments do
local x = tagCenter.x - vertices[i + ].x
local y = tagCenter.y + vertices[i + ].y table.insert(pPolygonPtArr, cc.p(x, y))
end -- 右上角
tagCenter.x = maxX - radius;
tagCenter.y = maxY - radius; for i = , 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 = , segments do
local x = tagCenter.x + vertices[i + ].x
local y = tagCenter.y - vertices[i + ].y table.insert(pPolygonPtArr, cc.p(x, y))
end -- 左下角
tagCenter.x = minX + radius;
tagCenter.y = minY + radius; for i = , 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(, , , )
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(+-, ++))
scene:addChild(head,) --配置参数
local TestRect = {}
TestRect.x =
TestRect.width =
TestRect.y=
TestRect.height = local TestBorderWidth =
local TestColor = cc.c4f(,,,)
local Testradius = head:clear()
drawNodeRoundRect(head,TestRect,TestBorderWidth,Testradius,TestColor,TestColor)

cocos2dx-lua 圆角矩形 圆角图片 drawNode的更多相关文章

  1. 使用imageMagick 制作圆角矩形和图片加水印

    制作圆角矩形好图片水印都是图片合成的操作 composite -gravity southeast mask175.png  src.jpg  dest.jpg -gravity southeast ...

  2. cocos2d-x lua 使用http(下载图片, POST JSON)

    cocos2d-x lua 使用http(下载图片, POST JSON) version: cocos2d-x 3.6 1.使用http post json与服务器交互 require(" ...

  3. Android开发之自定义圆角矩形图片ImageView的实现

    android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了,其原理就是首先获取到图片的Bitmap ...

  4. Android中绘制圆角矩形图片及任意形状图片

    圆角矩形图片在苹果的产品中很流行,相比于普通的矩形,很多人都喜欢圆角矩形的图片,因为它避开了直角的生硬,带来更好的用户体验,下面是几个设计的例子: 下面在Android中实现将普通的矩形图片绘制成圆角 ...

  5. Android开发之自定义圆角矩形图片ImageView的实现 - Jamy Cai

    android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了,其原理就是首先获取到图片的Bitmap ...

  6. [BOT] 一种android中实现“圆角矩形”的方法

    内容简介 文章介绍ImageView(方法也可以应用到其它View)圆角矩形(包括圆形)的一种实现方式,四个角可以分别指定为圆角.思路是利用"Xfermode + Path"来进行 ...

  7. swift UIImage加载远程图片和圆角矩形

    UIImage这个对象是swift中的图像类,可以使用UIImageView加载显示到View上. 以下是UIImage的构造函数: init(named name: String!) -> U ...

  8. Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示

    Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android实现圆角矩形,圆形或者椭圆等图形,一般通过自定义ImageView来实现,首先获取到图片的Bitmap,然后通过 ...

  9. 不用css样式表和背景图片实现圆角矩形,超简洁!

    当网站页面的整体布局设计好后,接下来有很多细节的实现是很让人头疼的.其中之一就是圆角矩形的实现. 在网上看了很多圆角矩形的实现方法,基本有两种,一种是用纯css实现,不需要背景图片:另一种是用背景图像 ...

随机推荐

  1. PS制作水火相溶特效文字图片

    最终效果 一.新建一个1400*900像素的画布. 二.由上到下拉一个深灰到纯黑径向渐变. 三.输入字母S,并用ctrl+t拉到适合的大小,并且降低不透明度. 四.拖入水花素材(如果大家有水花笔刷的话 ...

  2. 家庭记账本小程序之改(java web基础版五)

    实现修改消费账单 1.main_left.jsp中该部分,调用Servlet中的list方法 2.Servlet中的list方法,调用Dao层的list方法,跳转到list.jsp页面 3.Dao层的 ...

  3. 软工+C(1): 题目设计、点评和评分

    // 下一篇:分数和checklist 如何设计题目 教学中的一个问题是老师出题太简单了,题目设计一开始上来就不紧凑,我认为一个好的课程应该上来就给你紧凑感,而不是先上来"轻松2-3周&qu ...

  4. 在nginx上用FastCGI解析PHP

    nginx配置文件: Nginx 默认使用  include enable-php.conf;   通过enable-php.conf 来解析PHP,该文件内容如下 location ~ [^/]\. ...

  5. c指针作业(第一次)

    1. 数据类型的本质是什么? (从编译器的角度考虑) 数据类型可理解为创建变量的模具:是固定内存大小的别名 数据类型的作用:编译器预算对象(变量)分配的内存空间大小 注意:数据类型只是模具,编译器并没 ...

  6. error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    安装mysql是出现这个错误. python3.和python2.两个的版本不一样,所以安装的东西也不一样:MySQLdb 安装mysql的连接包.工具安装 Python3.x版本:Pip insta ...

  7. 解决Docker中运行的MySQL中文乱码

    docker exec -it mysql bash 如果没有安装vim,请参考 解决Docker容器中不能用vim编辑文件 vim /etc/mysql/mysql.conf.d/mysql.cnf ...

  8. linux服务端日志中截取自己所需要的部分

    近期开发一个图片处理的业务,涉及base64字符串解析的问题,为方便与友商间接口调试,日志中保存Base64.日,想想就肝儿疼,记录下来容易,取的时候难.为准确提取,配合两条命令即可. 1.获取日志所 ...

  9. <Android基础>(三) UI开发 Part 3 RecyclerView

    RecyclerView 1)RecyclerView的基本用法 2)横向滚动和瀑布流滚动 3)注册点击事件 3.6 强大的滚动控件 RecyclerView ListView缺点: 1.不使用技巧优 ...

  10. [curl]convert curl to python Ruby

    https://curl.trillworks.com/