• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
linux_ios
博客园    首页    新随笔    联系   管理    订阅  订阅

cocos2dx scheduleUpdate 更新函数

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    CCSprite* sp = CCSprite::create("Icon.png");
    sp->setPosition(ccp(100,100));
    addChild(sp,0,922);
  //  scheduleUpdate();
//    自定义更新函数 , 每一帧都调用
    schedule(schedule_selector(HelloWorld::myUpdate));
//    自定义更新函数 , 每秒执行一次
       schedule(schedule_selector(HelloWorld::myUpdate),1);
    return true;
}
void HelloWorld::myUpdate(float dt)
{
//          停止更新
    unschedule(schedule_selector(HelloWorld::myUpdate));
    
    CCSprite* sp = (CCSprite * )this->getChildByTag(922);
    if (sp->getPositionX()< 260) {
        sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,1)));
    }else{
        sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,-1)));
    }
}
void HelloWorld::update(float dt)
{
    CCSprite* sp = (CCSprite * )this->getChildByTag(922);
    if (sp->getPositionX()< 260) {
        sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,1)));
    }else{
        sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,-1)));
    }

}

 

posted @ 2013-04-04 11:06  linux_ios  阅读(1886)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3