【问题标题】:How to Draw Circle, incrementally, to create an animated fill effect (using Corona)如何逐步绘制圆形以创建动画填充效果(使用 Corona)
【发布时间】:2015-05-30 13:51:18
【问题描述】:

我什至不知道从哪里开始。任何帮助将不胜感激!

我想使用 Corona SDK 绘制一个随着百分比增加而逐渐填充的圆圈。

填充效果将跟随圆圈的路径,逆时针方向,直到整个圆圈/区域完全填充不同的颜色。

谢谢!

【问题讨论】:

  • 你有什么尝试过的吗?你真的得到了圆圈本身的绘图/工作吗?我们需要知道您尝试了哪些方法,哪些方法不起作用。像这样的案例经常被看不起,因为没有人愿意为你做所有的工作。
  • “我不知道从哪里开始。”似乎是一个相当合理的前兆,因为他的问题没有原型可供参考。在这种情况下,最好让问题一直存在,直到真正了解 Corona SDK 的人可以插话并提供一些帮助,并且可能编辑这个问题,直到它成为其他人的有价值的 Lua+Corona 社区资产做同样的事情。 (奇怪的是,我降落在这里的时候!)

标签: lua geometry coronasdk geometry-surface


【解决方案1】:

This sample from caronalabs.com forums 展示了如何绘制弧线,它提供了执行所需操作所需的离散算法:

function display.newArc(group, x,y,w,h,s,e,rot) 
    local theArc = display.newGroup()

    local xc,yc,xt,yt,cos,sin = 0,0,0,0,math.cos,math.sin --w/2,h/2,0,0,math.cos,math.sin
    s,e = s or 0, e or 360
    s,e = math.rad(s),math.rad(e)
    w,h = w/2,h/2
    local l = display.newLine(0,0,0,0)
    l:setColor(54, 251, 9)
    l.width = 4

    theArc:insert( l )

    for t=s,e,0.02 do 
        local cx,cy = xc + w*cos(t), yc - h*sin(t)
        l:append(cx,cy) 
    end

    group:insert( theArc )

    -- Center, Rotate, then translate       
    theArc.x,theArc.y = 0,0
    theArc.rotation = rot
    theArc.x,theArc.y = x,y

    return theArc
end

function display.newEllipse(group, x, y, w, h, rot)
    return newArc(group, x, y, w, h, nil, nil, rot)
end

看来您需要做的就是随着时间的推移继续从圆心向外分配新线。

免责声明:我尚未测试此代码,您可能需要进一步修改它,但乍一看数学看起来是正确的。

HTH!

【讨论】:

  • 对不起,我没有早点感谢你。这完全符合我的要求,谢谢!
猜你喜欢
  • 2020-07-10
  • 1970-01-01
  • 2018-06-03
  • 2013-05-13
  • 2020-04-27
  • 2016-09-26
  • 1970-01-01
  • 1970-01-01
  • 2021-01-25
相关资源
最近更新 更多