使用的官方类是: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. c语言之控制语句:循环

    #include<stdio.h> int main(void) { long num; long sum = 0L; int status; printf("Please en ...

  2. Vue项目搭建与部署

    Vue项目搭建与部署 一,介绍与需求 1.1,介绍 Vue  是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue两大核心思想:组件化和数据驱动.组 ...

  3. vue 使用微信JSSDK,在IOS端会授权出错

    原因: vue-router切换的时候操作的都是浏览器的历史记录,iOS会把第一次刚进入时的URL作为真实URL,安卓会把当前URL作为真实URL. 所以导致后端在配置好的授权参数获得的config参 ...

  4. Flask websocket

    websocket 概念 是一套协议,协议规定了: - 连接时需要握手 - 发送数据进行加密 - 连接之后不断开 意义 实现长轮询等操作 框架支持 - flask,gevent-websocket - ...

  5. php中fastcgi和php-fpm是什么东西

    参考和学习了以下文章: 1. mod_php和mod_fastcgi和php-fpm的介绍,对比,和性能数据 2. 实战Nginx_取代 为了如何一步步的引出fastcgi和php-fpm,我先一点一 ...

  6. [Nmap] Regular script

    out of date: TCP:nmap.exe -sC -sS -sV -p 1-65535 -A -v -v -oX filename.xml ip UDP:nmap.exe -sC -sU - ...

  7. 扩展CRT +扩展LUCAS

    再次感谢zyf2000超强的讲解. 扩展CRT其实就是爆推式子,然后一路合并,只是最后一个式子上我有点小疑惑,但整体还算好理解. #include<iostream> #include&l ...

  8. redis的主从模式搭建及注意事项

    前言:本文先分享下如何搭建redis的主从模式配置,以及主从模式配置的注意事项.后续会继续分享如何实现一个高可用的redis服务,redis的Sentinel 哨兵模式及集群搭建. 安装: 1,yum ...

  9. (一)Qt5模块,QtCreator常用快捷键,命名规范

    常用快捷键 1)帮助文件:F1 (光标在函数名字或类名上,按 F1 即可跳转到对应帮助文档,查看其详细用法) 2).h 文件和对应.cpp 文件切换:F4 3)编译并运行:Ctrl + R 4)函数声 ...

  10. 剑指Offer_编程题_21

    题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. class Solution { public: void push(int value) { st.push(val ...