– 执行无限循环动作
kathia:runAction(cc.RepeatForever:create(actionUp))
Helper.subtitleLabel:setString(“JumpTo / JumpBy”)
return layer
end
CardinalSplineBy类:基础曲线路径
– ActionCardinalSpline
– 曲线运动
local function ActionCardinalSpline()
local layer = cc.Layer:create()
initWithLayer(layer)
centerSprites(2)
– 位置数组
local array = {
cc.p(0, 0),
cc.p(size.width / 2 - 30, 0),
cc.p(size.width / 2 - 30, size.height - 80),
cc.p(0, size.height - 80),
cc.p(0, 0),
}
– 创建一个连续的基础曲线动作的点数组集合
local action = cc.CardinalSplineBy:create(3, array, 0)
– 返回执行与本Action对象相反操作的新Action对象
local reverse = action:reverse()
– 动作序列
local seq = cc.Sequence:create(action, reverse)
tamara:setPosition(cc.p(50, 50))
tamara:runAction(seq)
– 第一个参数是duration:持续时间,第二个参数为位置数组,第三个参数为tension,表示张力
local action2 = cc.CardinalSplineBy:create(3, array, 1)
local reverse2 = action2:reverse()
– 创建动作序列
local seq2 = cc.Sequence:create(action2, reverse2)
kathia:setPosition(cc.p(size.width / 2, 50))
kathia:runAction(seq2)
–[[
local function drawCardinalSpline()
kmGLPushMatrix()
kmGLTranslatef(50, 50, 0)
cc.DrawPrimitives.drawCardinalSpline(array, 0, 100)
kmGLPopMatrix()
kmGLPushMatrix()
kmGLTranslatef(size.width / 2, 50, 0)
cc.DrawPrimitives.drawCardinalSpline(array, 1, 100)
kmGLPopMatrix()
end
array:retain()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:registerScriptDrawHandler(drawCardinalSpline)
layer:addChild(glNode,-10)
glNode:setPosition( size.width / 2, size.height / 2)
]]–
Helper.titleLabel:setString(“CardinalSplineBy / CardinalSplineAt”)
Helper.subtitleLabel:setString(“Cardinal Spline paths.\nTesting different tensions for one array”)
return layer
end
CatmullRomBy类 :这是一个按照笛卡尔曲线移动目标点的动作.
**
**
– ActionCatmullRom
– 笛卡尔曲线运动
local function ActionCatmullRom()
local layer = cc.Layer:create()
initWithLayer(layer)
centerSprites(2)
– 设置精灵位置
tamara:setPosition(cc.p(50, 50))
– 定义位置数组
local array = {
cc.p(0, 0),
cc.p(80, 80),
cc.p(size.width - 80, 80),
cc.p(size.width - 80, size.height - 80),
cc.p(80, size.height - 80),
cc.p(80, 80),
cc.p(size.width / 2, size.height / 2),
}
– 创建笛卡尔曲线运动,第一个参数为持续时间,第二个参数为位置数组
local action = cc.CatmullRomBy:create(3, array)
local reverse = action:reverse()-- 相反操作
– 创建动作序列
local seq = cc.Sequence:create(action, reverse)
tamara:runAction(seq)
local array2 = {
cc.p(size.width / 2, 30),
cc.p(size.width -80, 30),
cc.p(size.width - 80, size.height - 80),
cc.p(size.width / 2, size.height - 80),
cc.p(size.width / 2, 30),
}
local action2 = cc.CatmullRomTo:create(3, array2)
local reverse2 = action2:reverse()
local seq2 = cc.Sequence:create(action2, reverse2)
kathia:runAction(seq2)
–[[
local function drawCatmullRom()
kmGLPushMatrix()
kmGLTranslatef(50, 50, 0)
cc.DrawPrimitives.drawCatmullRom(array, 50)
kmGLPopMatrix()
cc.DrawPrimitives.drawCatmullRom(array2,50)
end
array:retain()
array2:retain()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:registerScriptDrawHandler(drawCatmullRom)
layer:addChild(glNode,-10)
glNode:setPosition( size.width / 2, size.height / 2)
]]–
– 设置标题
Helper.titleLabel:setString(“CatmullRomBy / CatmullRomTo”)
Helper.subtitleLabel:setString(“Catmull Rom spline paths. Testing reverse too”)
return layer
end
BezierBy类:贝塞尔曲线动作。提供reverse方法,用于执行相反操作
BezierTo类:贝塞尔曲线动作。
******
– ActionBezier
– 贝塞尔曲线运动
local funct