1. Menu usage:
CCMenuItemimage * image = CCMenuItemImage * create ("xxx.png ",
"Xxx, png ",
"Xxx.png ",
This,
Menu_selector (HelloWorld: selfdefinefunc); // The first parameter is used when no image is selected, the second parameter is used when the image is selected, and the third parameter is: the image selected at the time of entry. Fourth parameter: on which object, fourth parameter: specific response function.
CCMenu * menu = CCMenu: create (iamge, NULL); // create a menu
Menu-> addChild (menu );
2. Actions executed by the genie:
CCMoveBy * moveby = CCMoveBy: create (2.0f, ccp (800,0 ));
CCCallFuncN * selfaction = CCCallFuncN: create (this, callfuncN_selector (HelloWorld: selfdefine); // CCCallFuncN is also an action, but this action is a callback function (with a parameter ).
CCSequence * action = CCSequence: create (moveby, selfaction, NULL); // combined action
Sprite1-> runAction (action );
3. How to enable the Timer:
Bool HelloWorld: init ()
{
// Omit a lot of code
This-> schedule (schedule_selector (HelloWorld: usecreatesprite), 2); // The first parameter is the response function, and the second parameter is the interval of execution.
Return true;
}
Void HelloWorld: usecreatesprite (float dt ){
Createsprite ();
}
Void HelloWorld: createsprite (){
CCSize visiblesize = CCDirector: sharedDirector ()-> getVisibleSize ();
CCSprite * sprite1 = CCSprite: create ("sprite.png"); // use local variables because many genie are to be created. Class Members are not applicable.
Int y = rand () % (int) (visiblesize. height );
Sprite1-> setPosition (ccp (10, y ));
This-> addChild (sprite1 );
CCMoveBy * moveby = CCMoveBy: create (2.0f, ccp (800,0 ));
CCCallFuncN * selfaction = CCCallFuncN: create (this, callfuncN_selector (HelloWorld: selfdefine ));
CCSequence * action = CCSequence: create (moveby, selfaction, NULL );
Sprite1-> runAction (action );
}
Q: Why is the createsprie function called in usecreatesprite (float dt) instead of being directly enabled when a timer is used?
Because the prototype of the execution function in schedule is fixed, the return value is void type, and the parameter type is float, while the createsprite function does not meet the requirements, the usecreatesprite function is used as a transitional function.