.h
# pragma once
# include "cocos2d. H"
The class MyCososAnimate: public cocos2d: : Node
{
Public:
MyCososAnimate ();
~ MyCososAnimate ();
Cocos2d: : Sprite * m_sprite=nullptr;
Cocos2d: : Animation * m_animation=nullptr;
Cocos2d: : the Animate * m_animate=nullptr;
Cocos2d: : ActionInterval * m_action=nullptr;
Bool MyRunAction ();
Virtual bool init (cocos2d: : Scene *);
The static MyCososAnimate * create (cocos2d: : Scene *);
};
.cpp
# include "MyCososAnimate. H"
Using the namespace cocos2d;
MyCososAnimate: : MyCososAnimate ()
{
}
MyCososAnimate: : ~ MyCososAnimate ()
{
}
MyCososAnimate * MyCososAnimate: : create (cocos2d: : Scene * _pScene) {
MyCososAnimate * pRet=new MyCososAnimate ();
If (pRet & amp; & amp; PRet - & gt; Init (_pScene))
{
PRet - & gt; Autorelease ();
}
The else
{
The delete pRet.
PRet=nullptr;
}
Return pRet.
}
Bool MyCososAnimate: : init (cocos2d: : Scene * _pScene) {
Auto visibleSize=Director: : getInstance () - & gt; GetVisibleSize ();
Vec2 origin=Director: : getInstance () - & gt; GetVisibleOrigin ();
//add "HelloWorld" splash screen "
M_sprite=Sprite: : create (" images/Down_01. PNG ");
VectorInt tmpSize=4;
AnimFrames. Reserve (4);
For (int I=1; I & lt;=tmpSize; I++)
{
Char tmpStr [50]={};
Sprintf_s (tmpStr, "images/Down_0 % d.p ng", I);
AnimFrames. PushBack (SpriteFrame: : create (tmpStr, the Rect (0, 0, 25, 41)));
}
//Animation * Animation=Animation: : createWithSpriteFrames (animFrames, 0.1 f);
//the Animate * the Animate=the Animate: : create (animation);
M_animation=Animation: : createWithSpriteFrames (animFrames, 0.1 f);
M_animate=the Animate: : create (m_animation);
M_animate - & gt; Retain ();
M_sprite - & gt; SetScale (2.0 f);
//run it and repeat it forever
M_action=CCRepeatForever: : create (m_animate);
//the position the Sprite on the center of the screen
M_sprite - & gt; SetPosition (Vec2 (visibleSize. Width/2 + origin. X, visibleSize. Height/2 + origin. Y));
//add the Sprite as a child to this layer
_pScene - & gt; AddChild (m_sprite, 0);
Return true;
}
Bool MyCososAnimate: : MyRunAction () {
M_sprite - & gt; RunAction (m_action);
Return true;
}
Click on the lower right corner in the HELLOWORLD button the animation
void HelloWorld: : menuCloseCallback (Ref * pSender)
{
TmpAni - & gt; MyRunAction ();
}
To RUNACTION error,,,
CodePudding user response:
DIRECTOR: : GETINSTANCE () - & gt; GetActionManager () - & gt; PauseTarget (node)If can solve pause, continue
CodePudding user response:
M_action=CCRepeatForever: : create (m_animate);//animation seems not so created? I remember that there is an Animation is like