cocos2dx-lua 圆角矩形 圆角图片 drawNode
使用的官方类是: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的更多相关文章
- 使用imageMagick 制作圆角矩形和图片加水印
制作圆角矩形好图片水印都是图片合成的操作 composite -gravity southeast mask175.png src.jpg dest.jpg -gravity southeast ...
- cocos2d-x lua 使用http(下载图片, POST JSON)
cocos2d-x lua 使用http(下载图片, POST JSON) version: cocos2d-x 3.6 1.使用http post json与服务器交互 require(" ...
- Android开发之自定义圆角矩形图片ImageView的实现
android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了,其原理就是首先获取到图片的Bitmap ...
- Android中绘制圆角矩形图片及任意形状图片
圆角矩形图片在苹果的产品中很流行,相比于普通的矩形,很多人都喜欢圆角矩形的图片,因为它避开了直角的生硬,带来更好的用户体验,下面是几个设计的例子: 下面在Android中实现将普通的矩形图片绘制成圆角 ...
- Android开发之自定义圆角矩形图片ImageView的实现 - Jamy Cai
android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了,其原理就是首先获取到图片的Bitmap ...
- [BOT] 一种android中实现“圆角矩形”的方法
内容简介 文章介绍ImageView(方法也可以应用到其它View)圆角矩形(包括圆形)的一种实现方式,四个角可以分别指定为圆角.思路是利用"Xfermode + Path"来进行 ...
- swift UIImage加载远程图片和圆角矩形
UIImage这个对象是swift中的图像类,可以使用UIImageView加载显示到View上. 以下是UIImage的构造函数: init(named name: String!) -> U ...
- Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示
Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android实现圆角矩形,圆形或者椭圆等图形,一般通过自定义ImageView来实现,首先获取到图片的Bitmap,然后通过 ...
- 不用css样式表和背景图片实现圆角矩形,超简洁!
当网站页面的整体布局设计好后,接下来有很多细节的实现是很让人头疼的.其中之一就是圆角矩形的实现. 在网上看了很多圆角矩形的实现方法,基本有两种,一种是用纯css实现,不需要背景图片:另一种是用背景图像 ...
随机推荐
- 常见的页面中两个div自适应等高CSS控制
第一种利用dispaly:table,父级div设置dispaly:table子级div设置display: table-cell; 第一种利用dispaly:flex,父级div设置dispaly: ...
- 《Effective C++》定制new和delete:条款49-条款52
条款49:了解new-handler的行为 当operator new无法分配出内存会抛出异常std::bad_alloc 抛出异常前会反复调用用户自定义的new-handler函数直至成功分配内存 ...
- 利用Python中SocketServer 实现客户端与服务器间非阻塞通信
利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信 版权声明 本文转自:http://blog.csdn.net/cnmilan/article/details/9664823 ...
- springdata 动态查询 是用来查询的 仅提供查询功能
springdata 动态查询 是用来查询的 仅提供查询功能
- 记录腾讯云中矿机病毒处理过程(重装系统了fu*k)
刚想学学kafka,登录与服务器看看把,谁知ssh特别慢,很奇怪,我以为是我网速问题,断了wifi,换了网线,通过iterm想要ssh root@x.x.x.x,但是上不去? 就tm的很奇怪了,登录腾 ...
- tmux 使用说明
安装Mac:brew install tmux若未安装libevent,需要先brew install libeventCentos:yum -y install tmuxUbuntu:apt-get ...
- 来了解质量管理工具——质量屋(HOQ)
质量屋(The House Of Quality),又名HOQ,它是质量功能配置(QFD)的核心.一般QFD的学习会涉及到.同时HOQ也是项目管理十大知识领域领域中质量管理工具中的一种,今天我们就来了 ...
- docker基本概念
详细参考https://www.jianshu.com/p/9deb6f41d5bd
- LVM备份(1)-创建LVM逻辑卷
LV(Logical Volume) - 逻辑卷 VG(Volume Group) - 卷组 PV(Physical Volume) - 物理卷 1.查看分区信息:fdisk -l 可看到磁盘大小为1 ...
- node安装express-generator脚手架
参考网址:https://www.jianshu.com/p/b555ba6f4067 全局安装: npm install express-generator -g 创建项目pro_test expr ...