Cocos2d-x 3.2 Lua示例 ActionTest(动作测试)
转自http://blog.csdn.net/wwj_748/article/details/38272837
本篇博客继续介绍Cocos2d-x的Lua示例,关于3.2的例子变动不是很大,稍微介绍一下3.2的新特性吧:
3.2版本的新特性
*新的3D动画节点Animation3D/Animate3D
*支持fbx-conv工具生成Sprite3D支持的二进制格式
*支持游戏手柄
*支持快速瓦片地图
*加入utils::cpatureScreen方法用于截屏
*Physicsbody支持缩放和旋转
*加入Node::enumerateChildren和utils::findChildren方法,且支持C++11的正则表达式
*加入Node::setNormalizedPosition方法,Node的位置像素会根据它的服节点的尺寸大小计算
想了解更多详细的内容,可以这个链接:http://cn.cocos2d-x.org/tutorial/show?id=1180
本篇博客继续介绍Lua的一个实例,这个实例基本上涵盖了Cocos2d-x的所有基本动作,在这个例子中Cocos2d-x Lua开发者可以了解到如何来使用这些动作。
小巫这里根据官网文档类给大家解析一遍,也顺便加深自己的印象:
注:笔者不把一大段代码贴出来,分段解释比较舒服一点
MoveBy:通过修改节点对象的位置属性来改变节点对象的x,y像素。 x,y的坐标是相对于这个对象的位置来说的。 几个MoveBy动作可以同时被调用,最终的运动是这几个单独运动的综合
MoveTo:移动节点对象到位置x,y。x,y是绝对坐标,通过修改它的位置属性来改变它们的值。 几个MoveTo动作可以被同时调用,并且最终的运动是几个单独运动的综合。
- --------------------------------------
- --ActionMove
- --动作移动
- --------------------------------------
- localfunctionActionMove()
- --创建层
- locallayer=cc.Layer:create()
- --初始化层
- initWithLayer(layer)
-
- centerSprites(3)
- --MoveBy动作
- localactionBy=cc.MoveBy:create(2,cc.p(80,80))
- --MoveBy的逆反操作
- localactionByBack=actionBy:reverse()
- --
- tamara:runAction(cc.MoveTo:create(2,cc.p(size.width-40,size.height-40)))
- grossini:runAction(cc.Sequence:create(actionBy,actionByBack))
- kathia:runAction(cc.MoveTo:create(1,cc.p(40,40)))
-
- Helper.subtitleLabel:setString("MoveTo/MoveBy")
- returnlayer
- end
ScaleTo:缩放动作
ScaleBy: 缩放动作,继承自ScaleTo,提供reverse方法
--ActionScale
- --动作缩放
- functionActionScale()
- locallayer=cc.Layer:create()
- --ScaleTo,第一个参数是缩放时间,第二个参数为缩放因子
- localactionTo=cc.ScaleTo:create(2.0,0.5)
- --ScaleBy,第一个参数为缩放时间,第二、三个参数为缩放因子
- localactionBy=cc.ScaleBy:create(2.0,1.0,10.0)
- localactionBy2=cc.ScaleBy:create(2.0,5.0,1.0)
- --执行动作
- grossini:runAction(actionTo)
- --执行动作序列,先正常缩放,然后反执行相反操作
- tamara:runAction(cc.Sequence:create(actionBy,actionBy:reverse()))
- kathia:runAction(cc.Sequence:create(actionBy2,actionBy2:reverse()))
- Helper.subtitleLabel:setString("ScaleTo/ScaleBy")
- returnlayer
- end
RotateBy类/RotateTo:旋转一个节点
--ActionRotate
- --动作旋转
- functionActionRotate()
- --RotateTo,第一个参数为持续时间,第二个参数为旋转角度
- localactionTo=cc.RotateTo:create(2,45)
- localactionTo2=cc.RotateTo:create(2,-45)
- localactionTo0=cc.RotateTo:create(2,0)
- --执行动作序列,先选择45度之后,
- tamara:runAction(cc.Sequence:create(actionTo,actionTo0))
- --RotateBy,持续时间为2秒,旋转360度
- localactionBy=cc.RotateBy:create(2,360)
- localactionByBack=actionBy:reverse()--相反操作
- localaction0Retain=cc.RotateTo:create(2,0)
- kathia:runAction(cc.Sequence:create(actionTo2,action0Retain))
- Helper.subtitleLabel:setString("RotateTo/RotateBy")
- end
SkewTo:通过修改节点对象的skewX和skewY属性来使节点对象倾斜到一个给定的角度。
SkewBy:通过skewX和skewY的度数来使节点对象倾斜。
--ActionSkew
- --斜歪动作
- functionActionSkew()
- --SkewTo,第一个参数是持续时间,第二个参数是X轴倾斜的角度,第三个是Y轴的倾斜角度
- localactionTo=cc.SkewTo:create(2,37.2,-37.2)
- localactionToBack=cc.SkewTo:create(2,0)--返回的一个动作
- localactionBy=cc.SkewBy:create(2,0.0,-90.0)
- localactionBy2=cc.SkewBy:create(2,45.0,45.0)
- --三个精灵执行动作序列
- kathia:runAction(cc.Sequence:create(actionBy2,actionBy2:reverse()))
- Helper.subtitleLabel:setString("SkewTo/SkewBy")
- end
--ActionRotationalSkewVSStandardSkew
- --轮转的倾斜动作和标准的倾斜动作
- functionActionRotationalSkewVSStandardSkew()
- initWithLayer(layer)
- --从父节点中删除一个节点,有一个cleanup参数。如果这个节点是一个孤节点,那么什么都不会发生。
- tamara:removeFromParent(true);
- grossini:removeFromParent(true);
- kathia:removeFromParent( --返回以点为单位的OpenGL视图的大小
- locals=cc.Director:getInstance():getWinSize();
- --宽高均为100的盒子
- localboxSize=cc.size(100.0,100.0);
- --创建层颜色块,c4b,第一个参数是r,代表红色,第二个参数是g,代表绿色,第三个参数是b,代表蓝色,第四个参数是a,代表透明度
- localbox=cc.LayerColor:create(cc.c4b(255,255));
- --设置锚点
- box:setAnchorPoint(cc.p(0.5,0.5));
- --设置盒子大小
- box:setContentSize(boxSize);
- --设置锚点为(0,0)当你摆放这个节点的时候。
- --这是一个内部方法,仅仅被Layer和Scene使用。不要在框架外调用。默认值是false,但是在Layer和Scene中是true.
- box:ignoreAnchorPointForPosition(false);
- --设置显示位置
- box:setPosition(cc.p(s.width/2,s.height-100-box:getContentSize().height/2));
- --添加到层中
- layer:addChild(box);
- --创建一个标签
- locallabel=cc.Label:createWithTTF("Standardcocos2dSkew",s_markerFeltFontPath,16);
- --设置锚点,这里是中心
- label:setAnchorPoint(cc.p(0.5,0.5))
- label:setPosition(cc.p(s.width/2,s.height-100+label:getContentSize().height));
- layer:addChild(label);
- --X轴倾斜360度
- localactionTo=cc.SkewBy:create(2,360,0);
- --动作返回
- localactionToBack=cc.SkewBy:create(2,-360,248)"> localseq=cc.Sequence:create(actionTo,actionToBack)
- --运行动作序列
- box:runAction(seq);
- --创建层黄颜色块,c4b,代表透明度
- box=cc.LayerColor:create(cc.c4b(255,255));
- box:setContentSize(boxSize);
- box:ignoreAnchorPointForPosition(false);
- layer:addChild(box);
- label=cc.Label:createWithTTF("RotationalSkew",248)"> label:setAnchorPoint(cc.p(0.5,0.5))
- label:setPosition(cc.p(s.width/2,s.height-250+label:getContentSize().height/2));
- layer:addChild(label);
- localactionTo2=cc.RotateBy:create(2,248)"> localactionToBack2=cc.RotateBy:create(2,0);
- seq=cc.Sequence:create(actionTo2,actionToBack2)
- Helper.subtitleLabel:setString("SkewComparison")
- returnlayer;
- end
--ActionSkewRotate
- --歪斜+旋转+缩放
- functionActionSkewRotate()
- --从父节点移除子节点
- true)
- true)
- --盒子大小
- --层颜色,第1、2、3分别为红绿篮颜色值,第4个为透明度值
- box:setAnchorPoint(cc.p(0,0))
- --设置位置
- box:setPosition(190,110)
- --设置内容大小
- box:setContentSize(boxSize)
- --标记大小
- localmarkrside=10.0
- localuL=cc.LayerColor:create(cc.c4b(255,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> box:addChild(uL)
- uL:setContentSize(cc.size(markrside,markrside))
- uL:setPosition(0,boxSize.height-markrside)
- uL:setAnchorPoint(cc.p(0,248)"> localuR=cc.LayerColor:create(cc.c4b(0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> box:addChild(uR)
- uR:setContentSize(cc.size(markrside,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> uR:setPosition(boxSize.width-markrside,248)"> uR:setAnchorPoint(cc.p(0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> layer:addChild(box)
- --三个动作SkewTo、RotateTo、ScaleTo
- localactionTo=cc.SkewTo:create(2,2)
- localrotateTo=cc.RotateTo:create(2,61.0)
- localactionScaleTo=cc.ScaleTo:create(2,-0.44,0.47)
- localactionScaleToBack=cc.ScaleTo:create(2,1.0)
- localrotateToBack=cc.RotateTo:create(2,248)"> --顺序执行三个动作序列
- box:runAction(cc.Sequence:create(actionTo,actionToBack))
- box:runAction(cc.Sequence:create(rotateTo,rotateToBack))
- box:runAction(cc.Sequence:create(actionScaleTo,actionScaleToBack))
- Helper.subtitleLabel:setString("Skew+Rotate+Scale")
- end
JumpTo类:模仿跳跃的轨迹移动节点
JumpBy类:模仿跳跃的轨迹移动节点.提供reverse方法
--ActionJump
- --跳的动作
- functionActionJump()
- centerSprites(3)
- --模仿跳跃的轨迹移动节点,第一个参数为持续时间,第二个参数为位置,第三个参数为跳的高度,第四个参数跳的次数
- localactionTo=cc.JumpTo:create(2,cc.p(300,300),50,4)
- localactionBy=cc.JumpBy:create(2,0),4)
- localactionUp=cc.JumpBy:create(2,cc.p(0,80,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> localactionByBack=actionBy:reverse()--相反操作
- --执行actionTo动作
- tamara:runAction(actionTo)
- --执行序列动作
- grossini:runAction(cc.Sequence:create(actionBy,actionByBack))
- --执行无限循环动作
- kathia:runAction(cc.RepeatForever:create(actionUp))
- Helper.subtitleLabel:setString("JumpTo/JumpBy")
- end
CardinalSplineBy类:基础曲线路径
--ActionCardinalSpline
- --曲线运动
- functionActionCardinalSpline()
- centerSprites(2)
- --位置数组
- localarray={
- cc.p(0,
- cc.p(size.width/2-30,
- cc.p(size.width/2-30,size.height-80),108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.p(0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> }
- --创建一个连续的基础曲线动作的点数组集合
- localaction=cc.CardinalSplineBy:create(3,array,248)"> --返回执行与本Action对象相反操作的新Action对象
- localreverse=action:reverse()
- --动作序列
- localseq=cc.Sequence:create(action,reverse)
- tamara:setPosition(cc.p(50,50))
- tamara:runAction(seq)
- --第一个参数是duration:持续时间,第二个参数为位置数组,第三个参数为tension,表示张力
- localaction2=cc.CardinalSplineBy:create(3,1)
- localreverse2=action2:reverse()
- --创建动作序列
- localseq2=cc.Sequence:create(action2,reverse2)
- kathia:setPosition(cc.p(size.width/2,50))
- kathia:runAction(seq2)
- --[[
- functiondrawCardinalSpline()
- kmGLPushMatrix()
- kmGLTranslatef(50,248)"> cc.DrawPrimitives.drawCardinalSpline(array,100)
- kmGLPopMatrix()
- kmGLPushMatrix()
- kmGLTranslatef(size.width/2,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.DrawPrimitives.drawCardinalSpline(array,1,100)
- kmGLPopMatrix()
- end
- array:retain()
- localglNode=gl.glNodeCreate()
- glNode:setContentSize(cc.size(size.width,size.height))
- glNode:setAnchorPoint(cc.p(0.5,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> glNode:registerScriptDrawHandler(drawCardinalSpline)
- layer:addChild(glNode,-10)
- glNode:setPosition(size.width/2,size.height/2)
- ]]--
- Helper.titleLabel:setString("CardinalSplineBy/CardinalSplineAt")
- Helper.subtitleLabel:setString("CardinalSplinepaths.nTestingdifferenttensionsforonearray")
- end
CatmullRomBy类 :这是一个按照笛卡尔曲线移动目标点的动作.
--ActionCatmullRom
- --笛卡尔曲线运动
- functionActionCatmullRom()
- --设置精灵位置
- --定义位置数组
- cc.p(80,80),248)"> cc.p(size.width-80,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.p(size.width-80,248)"> cc.p(80,248)"> cc.p(size.width/2,size.height/2),108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --创建笛卡尔曲线运动,第一个参数为持续时间,第二个参数为位置数组
- localaction=cc.CatmullRomBy:create(3,array)
- localreverse=action:reverse()--相反操作
- --创建动作序列
- localarray2={
- cc.p(size.width/2,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> localaction2=cc.CatmullRomTo:create(3,array2)
- localseq2=cc.Sequence:create(action2,reverse2)
- kathia:runAction(seq2)
- --[[
- localfunctiondrawCatmullRom()
- kmGLTranslatef(50,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.DrawPrimitives.drawCatmullRom(array,50)
- cc.DrawPrimitives.drawCatmullRom(array2,50)
- array2:retain()
- localglNode=gl.glNodeCreate()
- glNode:setContentSize(cc.size(size.width,size.height))
- glNode:setAnchorPoint(cc.p(0.5,248)"> glNode:registerScriptDrawHandler(drawCatmullRom)
- layer:addChild(glNode,-10)
- glNode:setPosition(size.width/2,size.height/2)
- ]]--
- --设置标题
- Helper.titleLabel:setString("CatmullRomBy/CatmullRomTo")
- Helper.subtitleLabel:setString("CatmullRomsplinepaths.Testingreversetoo")
- end
BezierBy类:贝塞尔曲线动作。提供reverse方法,用于执行相反操作
BezierTo类:贝塞尔曲线动作。
--ActionBezier
- --贝塞尔曲线运动
- functionActionBezier()
- --sprite1
- localbezier=ccBezierConfig()
- bezier.controlPoint_1=cc.p(0,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> bezier.controlPoint_2=cc.p(300,-size.height/2)
- bezier.endPosition=cc.p(300,248)"> --贝塞尔曲线配置结构
- localbezier={
- cc.p(300,-size.height/2),248)"> cc.p(300,100),248)"> --以持续时间和贝塞尔曲线的配置结构体为参数创建动作
- localbezierForward=cc.BezierBy:create(3,bezier)
- localbezierBack=bezierForward:reverse()
- --无限循环执行序列
- localrep=cc.RepeatForever:create(cc.Sequence:create(bezierForward,bezierBack))
- --sprite2
- tamara:setPosition(cc.p(80,160))
- localbezier2=ccBezierConfig()
- bezier2.controlPoint_1=cc.p(100,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> bezier2.controlPoint_2=cc.p(200,248)"> bezier2.endPosition=cc.p(240,160)
- localbezier2={
- cc.p(100,248)"> cc.p(200,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.p(240,160)
- }
- --创建贝塞尔曲线动作,第一个参数为持续时间,第二个参数为贝塞尔曲线结构
- localbezierTo1=cc.BezierTo:create(2,bezier2)
- --sprite3
- kathia:setPosition(cc.p(400,248)"> localbezierTo2=cc.BezierTo:create(2,248)"> --运行动作
- grossini:runAction(rep)
- tamara:runAction(bezierTo1)
- kathia:runAction(bezierTo2)
- Helper.subtitleLabel:setString("BezierTo/BezierBy")
- end
Blink类:闪烁动作
--ActionBlink
- --闪烁运动
- functionActionBlink()
- --创建两个闪烁动作,第一个参数为持续时间,第二个参数为闪烁次数
- localaction1=cc.Blink:create(2,10)
- localaction2=cc.Blink:create(2,5)
- --两个精灵执行动作
- tamara:runAction(action1)
- kathia:runAction(action2)
- Helper.subtitleLabel:setString("Blink")
- end
FadeTo类:渐变动作
FadeIn类:渐变动作 "reverse"动作是FadeOut
FadeOut类:渐变动作 "reverse"动作是FadeIn
--ActionFade
- --渐变动作
- function
ActionFade()
--设置透明度
tamara:setOpacity(0)
--创建淡进的动作
localaction1=cc.FadeIn:create(1)
--reverse动作,FadeOut
localaction1Back=action1:reverse()
--创建淡出的动作
localaction2=cc.FadeOut:create(1)
--reverse动作,FadeIn动作
localaction2Back=action2:reverse()
tamara:runAction(cc.Sequence:create(action1,action1Back))
kathia:runAction(cc.Sequence:create(action2,action2Back))
Helper.subtitleLabel:setString("FadeIn/FadeOut")
TintTo类:节点变色动作
TintBy类:节点变色动作,提供reverse方法。
--ActionTint
- --变色动作
- functionActionTint()
- --用持续时间和颜色创建动作,第一个参数为持续时间,后面三个为颜色值
- localaction1=cc.TintTo:create(2,255)
- localaction2=cc.TintBy:create(2,-127,-255,-127)
- Helper.subtitleLabel:setString("TintTo/TintBy")
- Animation类:一个用来在精灵对象上表现动画的动画对象.
AnimationCache类:动画缓存单例类。 如何你想要保存动画,你需要使用这个缓存
Animate类:创建序列帧动画
--ActionAnimate
- --动画动作
- functionActionAnimate()
- --创建动画
- localanimation=cc.Animation:create()
- localnumber,name
- fori=1,14do
- ifi<10then
- number="0"..i
- else
- number=i
- end
- name="Images/grossini_dance_"..number..".png"
- --用图片名称加一个精灵帧到动画中
- animation:addSpriteFrameWithFile(name)
- --shouldlast2.8seconds.Andthereare14frames.
- --在2.8秒内持续14帧
- animation:setDelayPerUnit(2.8/14.0)
- --设置"当动画结束时,是否要存储这些原始帧",true为存储
- animation:setRestoreOriginalFrame( --创建序列帧动画
- localaction=cc.Animate:create(animation)
- grossini:runAction(cc.Sequence:create(action,action:reverse()))
- --动画缓存单例类。如何你想要保存动画,你需要使用这个缓存。
- localcache=cc.AnimationCache:getInstance()
- --添加入一个动画到缓存,并以name作为标示
- cache:addAnimations("animations/animations-2.plist")
- --Returns查找并返回名了name的动画。如果找不到,返回NULL.
- localanimation2=cache:getAnimation("dance_1")
- --创建第二个序列帧动画
- localaction2=cc.Animate:create(animation2)
- --执行动作序列
- tamara:runAction(cc.Sequence:create(action2,action2:reverse()))
- --克隆一个动画
- localanimation3=animation2:clone()
- --设置循环次数
- animation3:setLoops(4)
- --创建一个序列帧动画
- localaction3=cc.Animate:create(animation3)
- kathia:runAction(action3)
- Helper.titleLabel:setString("Animation")
- Helper.subtitleLabel:setString("Center:Manualanimation.Border:usingfileformatanimation")
- end
Sequence类:顺序执行动作
--ActionSequence
- --动作序列
- functionActionSequence()
- alignSpritesLeft(1)
- --创建动作序列,第一个动作是MoveBy,第二个动作是RotateBy
- localaction=cc.Sequence:create(
- cc.MoveBy:create(2,cc.p(240,0)),108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cc.RotateBy:create(2,540))
- grossini:runAction(action)
- Helper.subtitleLabel:setString("Sequence:Move+Rotate")
- --------------------------------------
- --ActionSequence2
- --动作序列2
- localactionSequenceLayer=nil
- --动作序列回调1
- functionActionSequenceCallback1()
- --创建标签
- locallabel=cc.Label:createWithTTF("callback1called",16)
- label:setPosition(size.width/4,size.height/2)--设置显示位置
- --添加节点到层中
- actionSequenceLayer:addChild(label)
- --动作序列回调2
- functionActionSequenceCallback2(sender)
- locallabel=cc.Label:createWithTTF("callback2called",248)"> label:setPosition(cc.p(size.width/4*2,size.height/2))--设置显示位置
- --动作序列回调3
- functionActionSequenceCallback3(sender)
- locallabel=cc.Label:createWithTTF("callback3called",248)"> label:setPosition(cc.p(size.width/4*3,153); font-weight:bold; background-color:inherit">functionActionSequence2()
- actionSequenceLayer=cc.Layer:create()
- initWithLayer(actionSequenceLayer)
- grossini:setVisible(false)--设置节点不可见
- --创建一个顺序执行的动作,分别为Place:放置节点到某个位置,Show:显示节点;MoveBy:移动到(100,0)的位置;CallFunc:调用回调方法
- localaction=cc.Sequence:create(cc.Place:create(cc.p(200,200)),cc.Show:create(),cc.MoveBy:create(1,cc.p(100,cc.CallFunc:create(ActionSequenceCallback1),cc.CallFunc:create(ActionSequenceCallback2),cc.CallFunc:create(ActionSequenceCallback3))
- Helper.subtitleLabel:setString("SequenceofInstantActions")
- returnactionSequenceLayer
- Spawn类:并行动作
--ActionSpawn
- --同时执行一批动作
- functionActionSpawn()
- alignSpritesLeft(1)
- --创建一个并行动作,第一个动作为JumpBy,第二个动作为RotateBy
- localaction=cc.Spawn:create(
- cc.JumpBy:create(2,4),248)"> cc.RotateBy:create(2,720))
- --执行动作
- grossini:runAction(action)
- Helper.subtitleLabel:setString("Spawn:Jump+Rotate")
- end
Cocos2d-x 中相关动作提供reverse方法,用于执行Action的相反动作,一般以XXXBy这类的,都具有reverse方法
--ActionReverse
- --Action的相反动作
- functionActionReverse()
- --创建JumpBy动作
- localjump=cc.JumpBy:create(2,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --动作序列,第一个动作为跳跃的动作,第二个是跳的反操作
- localaction=cc.Sequence:create(jump,jump:reverse())
- Helper.subtitleLabel:setString("Reverseanaction")
- end
DelayTime类:延时动作
--ActionDelaytime
- --延迟动作
- functionActionDelaytime()
- --创建移动动作,移动到(150,0)位置
- localmove=cc.MoveBy:create(1,cc.p(150,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --第一个动作move,然后延迟2秒,再继续移动
- localaction=cc.Sequence:create(move,cc.DelayTime:create(2),move)
- Helper.subtitleLabel:setString("DelayTime:m+delay+m")
- end
Repeat类:重复执行动作很多次。次数由参数决定。 要无线循环动作,使用RepeatForever。
RepeatForever类:无线循环一个动作。 如果要循环有限次数,请使用Repeat动作。
--ActionRepeat
- --重复动作
- functionActionRepeat()
- alignSpritesLeft(2)
- --创建MoveBy动作,移动到(150,0)的位置
- locala1=cc.MoveBy:create(1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --创建重复执行的动作序列,这里重复3次
- localaction1=cc.Repeat:create(cc.Sequence:create(cc.Place:create(cc.p(60,60)),a1),3)
- --创建MoveBy动作,移动到(150,0)的位置
- locala2=cc.MoveBy:create(1,0))
- --创建重复执行的动作序列,这里无限重复执行
- localaction2=cc.RepeatForever:create(cc.Sequence:create(a2,a1:reverse()))
- --两个精灵分别执行动作
- kathia:runAction(action1)
- tamara:runAction(action2)
- Helper.subtitleLabel:setString("Repeat/RepeatForeveractions")
- --ActionRepeatForever
- --无限重复的动作
- functionrepeatForever(sender)
- localrepeatAction=cc.RepeatForever:create(cc.RotateBy:create(1.0,360))
- sender:runAction(repeatAction)
- functionActionRepeatForever()
- centerSprites(1)
- --创建一个动作序列,第一个动作先延时1秒,第二个动作调用无限重复的方法
- localaction=cc.Sequence:create(
- cc.DelayTime:create(1),248)"> cc.CallFunc:create(repeatForever))
- Helper.subtitleLabel:setString("CallFuncN+RepeatForever")
- --ActionRotateToRepeat
- --重复执行旋转的动作
- functionActionRotateToRepeat()
- centerSprites(2)
- --创建两个旋转的动作
- localact1=cc.RotateTo:create(1,90)
- localact2=cc.RotateTo:create(1,248)"> localseq=cc.Sequence:create(act1,act2)
- --一个无限重复的动作,一个重复10次的动作
- localrep1=cc.RepeatForever:create(seq)
- localrep2=cc.Repeat:create(seq:clone(),10)
- tamara:runAction(rep1)
- kathia:runAction(rep2)
- Helper.subtitleLabel:setString("Repeat/RepeatForever+RotateTo")
- CallFunc类:调用一个 'callback' 函数
--ActionCallFunc
- --调用方法
- localcallFuncLayer=nil
- --调用方法回调函数1
- functionCallFucnCallback1()
- locallabel=cc.Label:createWithTTF("callback1called",16)
- label:setPosition(size.width/4,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> callFuncLayer:addChild(label)
- --调用方法回调函数2
- functionCallFucnCallback2(sender)
- locallabel=cc.Label:createWithTTF("callback2called",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> label:setPosition(size.width/4*2,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --调用方法回调函数3
- functionCallFucnCallback3(sender)
- locallabel=cc.Label:createWithTTF("callback3called",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> label:setPosition(size.width/4*3,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --调用“Callback"
- functionActionCallFunc()
- callFuncLayer=cc.Layer:create()
- initWithLayer(callFuncLayer)
- --创建动作序列,第一个动作为MoveBy,第二个动作为CallFunc
- cc.CallFunc:create(CallFucnCallback1))
- --创建动作序列,第一个动作为ScaleBy,第二个动作为淡出,第三个动作为CallFunc
- localaction2=cc.Sequence:create(cc.ScaleBy:create(2,2),cc.FadeOut:create(2),cc.CallFunc:create(CallFucnCallback2))
- --创建动作序列,第一个动作为RotateBy,第二个动作w为淡出,第三个动作为CallFunc
- localaction3=cc.Sequence:create(cc.RotateBy:create(3,360),cc.CallFunc:create(CallFucnCallback3))
- --运行动作
- Helper.subtitleLabel:setString("Callbacks:CallFuncandfriends")
- returncallFuncLayer
- end
OrbitCamera类:创建一个带有起始半径、半径差、起始z角、旋转z角的差、起始x角、旋转x角的差 这些参数的运动视角动作类
--ActionOrbit
- --OrbitCamera类:action视角按照球面坐标轨迹围绕屏幕中心进行旋转
- functionActionOrbit()
- --创建一个带有起始半径、半径差、起始z角、旋转z角的差、起始x角、旋转x角的差这些参数的运动视角动作类
- localorbit1=cc.OrbitCamera:create(2,180,248)"> localaction1=cc.Sequence:create(orbit1,orbit1:reverse())
- localorbit2=cc.OrbitCamera:create(2,-45,248)"> localaction2=cc.Sequence:create(orbit2,orbit2:reverse())
- localorbit3=cc.OrbitCamera:create(2,90,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> localaction3=cc.Sequence:create(orbit3,orbit3:reverse())
- kathia:runAction(cc.RepeatForever:create(action1))
- tamara:runAction(cc.RepeatForever:create(action2))
- grossini:runAction(cc.RepeatForever:create(action3))
- localmove=cc.MoveBy:create(3,-100))
- localmove_back=move:reverse()
- localseq=cc.Sequence:create(move,move_back)
- localrfe=cc.RepeatForever:create(seq)
- kathia:runAction(rfe)
- tamara:runAction(rfe:clone())
- grossini:runAction(rfe:clone())
- Helper.subtitleLabel:setString("OrbitCameraaction")
- end
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|