_Curve

曲线类,用于构造曲线、画线 全部展开

属性展开

  • + type :uint

    曲线类型

静态常量展开

  • + Hermite :uint

    枚举值,曲线类型:诶尔米特曲线

  • + Straight :uint

    枚举值,曲线类型:直线。

构造方法展开

  • + function _Curve() : _Curve

    构造一条曲线

    • 返回
    • 新构造的曲线,没有任何关键点。
    • 示例

       c = _Curve.new()

公共方法展开

  • + function addPoint(p : _Vector2)

    添加点

    • 参数
    • _Vector2对象
    • 示例

       c:addPoint(_Vector.new(50, 50))
  • + function clearPoints()

    清空关键点

    • 示例

       c:clearPoints() 
  • + function delPoint(index : uint)

    删除关键点

    • 参数
    • 点的索引下标
    • 示例

       c:delPoint(1)
  • + function draw()

    画线

    • 示例

       c:draw()
  • + function getPoint(index : unit)

    获得某个关键点

    • 参数
    • 点的索引下标
    • 示例

       c:getPoint(1)
  • + function getPoints() : array

    获得所有关键点

    • 返回
    • 关键点数组
    • 示例

       c:getPoints()
  • + function getValue(t : float) : _Vector2

    得到线上某一时刻的值

    • 参数
    • 0~1的浮点数
    • 返回
    • 这一时刻线上对应的点
    • 示例

       p = c:getValue(0.5)
      print(p.x, p.y)

代码示例

    local curve = _Curve.new()
    curve:addPoint(_Vector2.new( 0,20 ))
    curve:addPoint(_Vector2.new( 50,10 ))
    curve:addPoint(_Vector2.new( 60,10 ))
    curve:addPoint(_Vector2.new( 80,50 ))
    curve:addPoint(_Vector2.new( 100,60 ))
    curve:addPoint(_Vector2.new( 150,100 ))

    _app:onIdle(function(e)
    curve:draw( 100, 100, _Color.White )
    end)

    _app:onKeyDown(function(key)
    if key == _System.Key1 then
    curve.type = _Curve.Straight
    elseif key == _System.Key2 then
    curve.type = _Curve.Hermite
    elseif key == _System.KeyA then
    local point = curve:getValue( 0.5 )
    print( '0.5Value:', point.x, point.y)
    elseif key == _System.KeyS then
    local point = curve:getPoint(2)
    print( '2Point:', point.x, point.y)
    elseif key == _System.KeyD then
    local points = curve:getPoints()
    print( '#Points:', #points)
    end
    end)
问题反馈(登录才可以发表哦!)