cocos2dx-lua给文字添加下划线

给文字添加下划线,其实也就是画一条直线,只是直线放在了文字下方而已

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- 创建并返回一个 DrawNode (线性)对象。
-- @function [parent=#display] newLine
-- @param table point table
-- @param table params 有参数,边线色 borderColor 及边线宽度 borderWidth
-- @return DrawNode#DrawNode ret (return value: cc.DrawNode)
-- @see ShapeNode


--[[--

创建并返回一个 DrawNode (线性)对象。

格式:

shape = display.newLine(point表, [参数])


-- 创建一个线宽为2,颜色为红色,从(10,10)到(100,100)的线段
local shape3 = display.newLine({{10, 10}, {100,100}},
{borderColor = cc.c4f(1.0, 0.0, 0.0, 1.0),
borderWidth = 1})
]]

function display.newLine(points, params)
local radius
local borderColor
local scale

if not params then
borderColor = cc.c4f(0,0,0,1)
radius = 0.5
scale = 1.0
else
borderColor = params.borderColor or cc.c4f(0,0,0,1)
radius = (params.borderWidth and params.borderWidth/2) or 0.5
scale = checknumber(params.scale or 1.0)
end

for i, p in ipairs(points) do
p = cc.p(p[1] * scale, p[2] * scale)
points[i] = p
end

local drawNode = cc.DrawNode:create()
drawNode:drawSegment(points[1], points[2], radius, borderColor)

return drawNode
end