cocos2dx中update()的参数如何传入的?

wyl1267 2015-01-30 09:55:03
请问cocos2dx中update(float dt)的参数dt代表什么? 是如何传入的?
...全文
290 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
没品的怪蜀黍 2015-02-06
  • 打赏
  • 举报
回复
是时间,一般都在开启时间调度的时候传入
wyl1267 2015-02-02
  • 打赏
  • 举报
回复
自己顶一下,求答复...
cocos2dx 雷电MoonWarriors_游戏源码 #include "GameLayer.h" #include "SimpleAudioEngine.h" #include "Bullet.h" #include "Resource.h" #include "Config.h" #include "Enemy.h" #include "Effect.h" #include "GameOver.h" #include "PauseLayer.h" using namespace cocos2d; using namespace CocosDenshion; bool isPaused = false; GameLayer::GameLayer():m_state(statePlaying),m_time(0),m_ship(NULL),m_backSky(NULL),m_backSkyHeight(0),m_backSkyRe(NULL),m_backTileMap(NULL),m_backTileMapHeight(0),m_backTileMapRe(NULL),m_isBackSkyReload(false),m_isBackTileReload(false),m_lbScore(NULL),m_lifeCount(NULL), m_tempScore(0) { } GameLayer::~GameLayer() { if (m_levelManager) { delete m_levelManager; } play_bullet->release(); enemy_bullet->release(); enemy_items->release(); } bool GameLayer::init() { if (!CCLayer::init()) { return false; } // 开启触摸 this->setTouchEnabled(true); // 创建数组,需要retain一下 play_bullet = CCArray::create(); play_bullet->retain(); enemy_bullet = CCArray::create(); enemy_bullet->retain(); enemy_items = CCArray::create(); enemy_items->retain(); m_state = statePlaying; Enemy::sharedEnemy(); Effect::sharedExplosion(); Config::sharedConfig()->resetConfig(); winSize = CCDirector::sharedDirector()->getWinSize(); m_levelManager = new LevelManager(this); //初始化背景 initBackground(); m_screenRec = CCRectMake(0, 0, winSize.width, winSize.height + 10); // score m_lbScore = CCLabelBMFont::create("Score:0", s_arial14_fnt); m_lbScore->setAnchorPoint(ccp(1, 0)); m_lbScore->setAlignment(kCCTextAlignmentRight); addChild(m_lbScore, 1000); m_lbScore->setPosition(winSize.width - 5, winSize.height - 30); // ship life CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01); CCSprite *life = CCSprite::createWithTexture(shipTexture, CCRectMake(0, 0, 60, 38)); life->setScale(0.6); life->setPosition(ccp(30,winSize.height-23)); addChild(life, 1, 5); // ship life count char lifecount[2]; sprintf(lifecount, "%d",Config::sharedConfig()->getLifeCount()); m_lifeCount = CCLabelTTF::create(lifecount, "Arial", 20); m_lifeCount->setPosition(ccp(60, winSize.height-20)); m_lifeCount->setColor(ccc3(255,0, 0)); addChild(m_lifeCount, 1000); // ship m_ship = Ship::create(); addChild(m_ship, m_ship->getZoder(), 1001); CCMenuItemImage *pause = CCMenuItemImage::create("pause.png", "pause.png", this, menu_selector(GameLayer::doPause)); pause->setAnchorPoint(ccp(1, 0)); pause->setPosition(ccp(winSize.width, 0)); CCMenu *menu = CCMenu::create(pause, NULL); menu->setAnchorPoint(ccp(0, 0)); addChild(menu, 1, 10); menu->setPosition(CCPointZero); // 调 update函数 scheduleUpdate(); // 每秒调一次 scoreCounter函数 schedule(schedule_selector(GameLayer::scoreCounter), 1); if (Config::sharedConfig()->getAudioState()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_bgMusic, true); } return true; } void GameLayer::update(float dt) { if (m_state == statePlaying) { checkIsCollide(); removeInactiveUnit(dt); checkIsReborn(); updateUI(); } } void GameLayer::scoreCounter() { if (m_state == statePlaying) { m_time++; m_levelManager->loadLevelResource(m_time); } } void GameLayer::checkIsCollide() { CCObject *units; CCObject *bullets; CCObject *enemybs; CCARRAY_FOREACH(enemy_items, units) { UnitSprite *enemy = dynamic_cast(units); CCARRAY_FOREACH(play_bullet, bullets) { UnitSprite *bullet = dynamic_cast(bullets); if (this->collide(enemy, bullet)) { enemy->hurt(); bullet->hurt(); } if (!(m_screenRec.intersectsRect(bullet->boundingBox()))) { bullet->destroy(); } }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧