HappyCoding:] ChildhoodAndy

思维世界的发展,在某种意义上说,就是对惊奇的不断摆脱。——爱因斯坦

quick-cocos2d-x最新CCDrawNodeExtend测试

| Comments

Jacky大神最近push了一个request,包含了两个重要的特性

  • CCDrawNodeExtend drawNode绘制包括点、圆、多边形等
  • filters滤镜支持

针对drawNode做了一些绘制测试,随后把代码贴了上来

CCDrawNodeExtend Test
local MainScene = class("MainScene", function()
    return display.newScene("MainScene")
end)

function MainScene:ctor()
    self.canvas = display.newDrawNode():addTo(self)

    -- draw a polygon

    self.canvas:drawPol({{100, 100}, {200, 200}, {150, 200}}, {fillColor = cc.c4f(1, 0, 0, 1), borderColor = cc.c4f(0, 1, 0, 1), borderWidth = 1})

    -- draw a circle

    self.canvas:drawCircle(ccp(500, 500), 50, {fillColor = cc.c4f(1, 0, 0, 1), borderColor = cc.c4f(0, 1, 0, 1), borderWidth = 3})
    self.canvas:drawCircle({700, 200}, 100, {
         fillColor = cc.c4f(1, 0, 0, 1), 
         borderColor = cc.c4f(0, 1, 0, 1), 
         borderWidth = 0.5, 
         segments = 50,
         startAngle = 30,
         endAngle = 500,
         })

    -- draw a dot

    self.canvas:drawDot(ccp(500, 100), 20, cc.c4f(0, 1, 1, 1))

    -- draw a rect

    self.canvas:drawRect({x = 400, y = 300, w = 100, h = 100}, {fillColor = cc.c4f(1, 0, 0, 1), borderColor = cc.c4f(0, 1, 0, 1), borderWidth = 1})
    self.canvas:drawRect({500, 200, 100, 100}, {fillColor = cc.c4f(1, 0, 0, 1), borderColor = cc.c4f(0, 1, 0, 1), borderWidth = 1})
    self.canvas:drawRect(cc.rect(100, 600, 20, 20), {fillColor = cc.c4f(1, 0, 0, 1), borderColor = cc.c4f(1, 1, 0, 1), borderWidth = 1})

    -- draw a line

    for i = 1, 20 do
        self.canvas:drawLine({100 + 20 * i, 20 + 20 * (i % 2)}, {100 + 20 * (i + 1), 20 + 20 * ((i + 1) % 2)}, 2, cc.c4f(0, 1, 1, 1))
    end
end

return MainScene

运行截图

使用起来很方便,啊哈?
上述代码中的drawCircle的源码我进行了修改,使得绘制时支持设定圆心坐标,已经给Jacky发了pull request

Comments

comments powered by Disqus