使用的官方类是: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. jQuery实现单击某个标签改变样式

    1.HTML代码,如下图: <p class="sc_member_recharge_form"> <span class="selected" ...

  2. 工具(3): 转换Excel表格到MarkDown:exceltk

    源码和下载: 0.1.3 mac: https://github.com/fanfeilong/exceltk/blob/master/pub/exceltk.0.1.3.pkg windows: h ...

  3. 写论文时,使用word的一些技巧

    目录 怎么设置文章里所有英文的字体.所有中文的字体样式 删除文章中的所有或者部分超链接 设置忽略英文的拼写检查 怎么设置文章里所有英文字体.所有中文字体样式 用鼠标选中需要更改的文章内容,如果是全文, ...

  4. js04-DOM对象一

    一.什么是HTML  DOM HTML  Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 HTML 文档呈现 ...

  5. mpvue——支持less

    安装 安装less和less-loader,我用的是淘宝源,你也可以直接npm $ cnpm install less less-loader --save 配置 打开build目录下的webpack ...

  6. SQL学习指南之查询入门

    查询语句 select语句由几个组件或者说子句构成.不过在MySQL中,只有一种子句是必不可少的(select子句),通常的查询语句会至少包含6个子句中的2~3个.下面的表列出了用于不同目的的各个子句 ...

  7. LVM备份(3)- pg_dumpall

  8. echarts地图详解

    $(function() { // 路径配置 require.config({ paths : { // echarts: 'http://echarts.baidu.com/build/dist' ...

  9. Tensorflow基本语法

    一.tf.Variables() import tensorflow as tf Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) se ...

  10. ZooKeeper-配置 zoo.cfg

    官方说明:https://zookeeper.apache.org/doc/r3.4.14/zookeeperAdmin.html#sc_configuration # 通信心跳数,Zookeeper ...