// // HelloWorldScene.h // #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; class HelloWorld : public cocos2d::CCLayer { public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld); virtual void update(float dt); virtual void myUpdate(float dt); virtual void moreUpdate(float dt); }; #endif
// // HelloWorldScene.cpp // #include "HelloWorldScene.h" USING_NS_CC; CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *spr = CCSprite::create("Icon-57.png"); spr->setPosition(ccp(winSize.width*0.5,winSize.height*0.5)); this->addChild(spr,290); this->scheduleUpdate(); this->schedule(schedule_selector(HelloWorld::myUpdate)); this->schedule(schedule_selector(HelloWorld::moreUpdate),2.0f); return true; } void HelloWorld::update(float dt) { CCLog("HelloWorld::update"); CCSprite *spr = (CCSprite *)this->getChildByTag(290); if (spr->getPositionX() < 260) { spr->setPosition(ccpAdd(spr->getPosition(),ccp(1,1))); } else { spr->setPosition(ccpAdd(spr->getPosition(),-1))); } } void HelloWorld::myUpdate(float dt) { CCLog("HelloWorld::myUpdate"); } void HelloWorld::moreUpdate(float dt) { CCLog("HelloWorld::moreUpdate"); this->unscheduleUpdate(); // 停止默认的update更新函数 this->unschedule(schedule_selector(HelloWorld::myUpdate)); // 停止自定义的更新函数 this->unscheduleAllSelectors(); // 停止所有的更新函数 }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。