1.移动
//------------------------------------------------------------------ // ActionMove // 动作:移动 // CCMoveBy 创建一个移动的动作 // 参数1:移动到目标坐标所需的时间 // 参数2:目标坐标 支持reverse 可以获取其反向动作 //------------------------------------------------------------------ void ActionMove::onEnter() { ActionsDemo::onEnter(); centerSprites(3); //获得屏幕的中心位置 auto s = Director::getInstance()->getWinSize(); //2秒内到达,这个位置Vec2(s.width-40,s.height-40) auto actionTo = MoveTo::create(2,Vec2(s.width-40,s.height-40)); //2秒内,移动的单位矢量Vec2(80,80) auto actionBy = MoveBy::create(2,Vec2(80,80)); //2秒后,开始还原actionBy auto actionByBack = actionBy->reverse(); _tamara->runAction( actionTo); _grossini->runAction( Sequence::create(actionBy,actionByBack,nullptr)); //1秒内,到达Vec2(40,40)这个位置 _kathia->runAction(MoveTo::create(1,Vec2(40,40))); }
2.放大或缩小
//------------------------------------------------------------------ // // ActionScale // CCScaleBy 作用:创建一个缩放的动作 // 参数1:达到缩放大小的所需时间 // 参数2:缩放比例 // //------------------------------------------------------------------ void ActionScale::onEnter() { ActionsDemo::onEnter(); centerSprites(3); //2秒内大小,整体缩小到原来的0.5倍 auto actionTo = ScaleTo::create(2.0f,0.5f); //2秒内大小,x轴不变,y轴放大到原来的10倍 auto actionBy = ScaleBy::create(2.0f,1.0f,10.0f); //2秒内大小,x轴放大到原来的5倍,y轴不变 auto actionBy2 = ScaleBy::create(2.0f,5.0f,1.0f); //执行actionTo _grossini->runAction( actionTo); //先执行actionBy,2秒后,大小反转变化,最终恢复到原始大小 _tamara->runAction( Sequence::create(actionBy,actionBy->reverse(),nullptr)); _kathia->runAction( Sequence::create(actionBy2,actionBy2->reverse(),nullptr)); }
3.旋转
//------------------------------------------------------------------ // ActionRotate // RotateTo作用创建一个旋转的动作 // 参数1:旋转的时间 // 参数2:旋转的角度,正数表示顺时针,负数逆时针方向 //------------------------------------------------------------------ void ActionRotate::onEnter() { ActionsDemo::onEnter(); centerSprites(3); auto actionTo = RotateTo::create( 2,45); auto actionTo2 = RotateTo::create( 2,-45); auto actionTo0 = RotateTo::create(2,0); //前2秒内,顺时针旋转到45度,后2秒内,旋转到0度 _tamara->runAction( Sequence::create(actionTo,actionTo0,nullptr)); auto actionBy = RotateBy::create(2,360); auto actionByBack = actionBy->reverse(); //前两秒内,顺时针旋转360度,后2秒,逆方向旋转,最后恢复到初始角度 _grossini->runAction( Sequence::create(actionBy,nullptr)); //前2秒内,逆时针旋转到45度,后2秒内,旋转到0度 _kathia->runAction( Sequence::create(actionTo2,actionTo0->clone(),nullptr)); }
4.拉伸
//------------------------------------------------------------------ // ActionSkew // SkewTo作用创建一个倾斜的动作 // 参数1:倾斜到特定角度所需的时间 // 参数2:x轴的倾斜角度,(正值表示屏幕向右的方向,反之,则向左) // 参数3:y轴的倾斜角度,(正值表示屏幕向里的方向,反之,则屏幕向外的方向) // 如果参数2和参数3的同为正或同为负,则拉伸的会变扭曲,如果一负一正,则拉伸不扭曲 //------------------------------------------------------------------ void ActionSkew::onEnter() { ActionsDemo::onEnter(); centerSprites(3); //2秒内,x轴向右倾斜37.2度,y轴向屏幕里面倾斜37.2度,同为正数,拉伸变扭曲 auto actionTo = SkewTo::create(2,37.2f,37.2f); //2秒内,actionTo倾斜度还原 auto actionToBack = SkewTo::create(2,0); //2秒内,x轴不倾斜,y轴向屏幕外面倾斜90度 auto actionBy = SkewBy::create(2,0.0f,-90.0f); //2秒内,x轴向左倾斜45度,y轴向屏幕里面倾斜45度,一负一正,拉伸不扭曲 auto actionBy2 = SkewBy::create(2,-45.0f,45.0f); auto actionByBack = actionBy->reverse(); _tamara->runAction(Sequence::create(actionTo,actionToBack,nullptr)); _grossini->runAction(Sequence::create(actionBy,nullptr)); _kathia->runAction(Sequence::create(actionBy2,nullptr)); }