bool HighscoreLayer::init() { if(!LayerColor::init()) { return false; } Director* director = Director::getInstance(); Vec2 visibleOrigin = director->getVisibleOrigin(); Size visibleSize = director->getVisibleSize(); // setContentSize(visibleSize); Widget* root = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/high_score.json"); addChild(root); root->setContentSize(visibleSize); Node* content = root->getChildByName("content"); content->setPositionY((visibleSize.height-content->getContentSize().height)/2); Text* endlessHighscoreLabel = dynamic_cast<Text*>(content->getChildByName("endlessHighScoreLabel")); endlessHighscoreLabel->setString(LANG->getLang("high_score_endless_label")); Text* endlessHighscoreText = dynamic_cast<Text*>(content->getChildByName("endlessHighscoreText")); endlessHighscoreText->setString(StringUtils::format("%d", UserData::getInstance()->getEndlessHighscore())); Text* classicHighscoreLabel = dynamic_cast<Text*>(content->getChildByName("classicHighScoreLabel")); classicHighscoreLabel->setString(LANG->getLang("high_score_classic_label")); Text* classicHighscoreText = dynamic_cast<Text*>(content->getChildByName("classicHighscoreText")); classicHighscoreText->setString(StringUtils::format("%d", UserData::getInstance()->getClassicHighscore())); Util::registerButton(root, "back", [=](Ref* ref,Widget::TouchEventType event){ switch (event) { case cocos2d::ui::Widget::TouchEventType::ENDED: { Director::getInstance()->replaceScene(MainMenuLayer::createScene()); } break; default: break; } }, ""); Node* backButton = root->getChildByName("back"); auto backButtonSize = backButton->getContentSize(); backButton->setPosition(backButtonSize.width/2+20, visibleSize.height-backButtonSize.height/2 - 15); Text* title = dynamic_cast<Text*>(content->getChildByName("title")); title->setString(LANG->getLang("high_score_title")); return true; }
void RenderTexture::onBegin() { // Director *director = Director::getInstance(); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); _oldTransMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _transformMatrix); if(!_keepMatrix) { director->setProjection(director->getProjection()); const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; Mat4 orthoMatrix; Mat4::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } //calculate viewport { Rect viewport; viewport.size.width = _fullviewPort.size.width; viewport.size.height = _fullviewPort.size.height; float viewPortRectWidthRatio = float(viewport.size.width)/_fullRect.size.width; float viewPortRectHeightRatio = float(viewport.size.height)/_fullRect.size.height; viewport.origin.x = (_fullRect.origin.x - _rtTextureRect.origin.x) * viewPortRectWidthRatio; viewport.origin.y = (_fullRect.origin.y - _rtTextureRect.origin.y) * viewPortRectHeightRatio; //glViewport(_fullviewPort.origin.x, _fullviewPort.origin.y, (GLsizei)_fullviewPort.size.width, (GLsizei)_fullviewPort.size.height); glViewport(viewport.origin.x, viewport.origin.y, (GLsizei)viewport.size.width, (GLsizei)viewport.size.height); } // Adjust the orthographic projection and viewport glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); glBindFramebuffer(GL_FRAMEBUFFER, _FBO); // TODO: move this to configuration, so we don't check it every time /* Certain Qualcomm Adreno GPU's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. */ if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { // -- bind a temporary texture so we can clear the render buffer without losing our texture glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); CHECK_GL_ERROR_DEBUG(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); } }
void SpriteManager::win() { batchNode->removeChild(allSp[0],true); Director *director = Director::getInstance(); director->pause();//暂停各种运动 createSprite(NULL, Rect(419,652,619-419,708-652), batchNode, 0.5, 0.5, WIDTH/2, HEIGHT/2, 500, 200, PauseBGZOrder+1); //左上角 的返回键按钮 allSp[23] = createSprite(NULL, Rect(871,154,910-871,186-154), batchNode, 0.5f, 0.5f, 45, 540-37, 63, 55, GoBackZOrder); allSp[23]->setRotation(-90.0f); AddEventListenerSprite(allSp[23]); }
void RenderTexture::end() { Director *director = Director::getInstance(); glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); // restore viewport director->setViewport(); kmGLMatrixMode(KM_GL_PROJECTION); kmGLPopMatrix(); kmGLMatrixMode(KM_GL_MODELVIEW); kmGLPopMatrix(); }
Node::Node(void) : _rotationX(0.0f) , _rotationY(0.0f) , _scaleX(1.0f) , _scaleY(1.0f) , _vertexZ(0.0f) , _position(Point::ZERO) , _skewX(0.0f) , _skewY(0.0f) , _anchorPointInPoints(Point::ZERO) , _anchorPoint(Point::ZERO) , _contentSize(Size::ZERO) , _additionalTransform(AffineTransformMakeIdentity()) , _camera(NULL) // children (lazy allocs) // lazy alloc , _grid(NULL) , _ZOrder(0) , _children(NULL) , _parent(NULL) // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true , _tag(kNodeTagInvalid) // userData is always inited as nil , _userData(NULL) , _userObject(NULL) , _shaderProgram(NULL) , _GLServerState(ccGLServerState(0)) , _orderOfArrival(0) , _running(false) , _transformDirty(true) , _inverseDirty(true) , _additionalTransformDirty(false) , _visible(true) , _ignoreAnchorPointForPosition(false) , _reorderChildDirty(false) , _isTransitionFinished(false) , _updateScriptHandler(0) , _componentContainer(NULL) { // set default scheduler and actionManager Director *director = Director::getInstance(); _actionManager = director->getActionManager(); _actionManager->retain(); _scheduler = director->getScheduler(); _scheduler->retain(); ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); _scriptType = pEngine != NULL ? pEngine->getScriptType() : kScriptTypeNone; _componentContainer = new ComponentContainer(this); }
void HealthMonitor::update() { Director* director = static_cast<Director*>(backend_->manager()); setRequest( "GET %s HTTP/1.1\r\n" "Host: %s\r\n" "x0-Health-Check: yes\r\n" "x0-Director: %s\r\n" "x0-Backend: %s\r\n" "\r\n", director->healthCheckRequestPath().c_str(), director->healthCheckHostHeader().c_str(), director->name().c_str(), backend_->name().c_str()); }
int main() { Director* d = new Director(); d->setBuilder(new dfBuilder()); d->orderCake("sacher"); d->orderCake("tresLeches"); d->orderCake("imposible"); d->orderCake("imposible"); d->orderCake("imposible"); d->printCakes(); std::cout << "Tenemos " << d->getCakesCount() << " pasteles" << std::endl; std::cout << "Hay un imposible en la posicion " << d->searchCake("imposible") << std::endl; d->searchCake("tresLeches"); return 0; }
void Enemy::die() { rewardPlayer(); // initialize director Director *pDirector = Director::getInstance(); // create a scene. it's an autorelease object Scene *pScene = VictoryScene::scene(); // run pDirector->pushScene(pScene); //delete player; //delete this; }
//------------------------------------------------------------------ // // MainGameLayer3 // //------------------------------------------------------------------ bool MainGameLayer3::init() { iMaxFeet = MAX_DIVE_FEET_AT_ONE_SCENE; iTagForMarinelife = kTagLayerSquid; // Add background sprite addBackground(); // Touch Director* director = Director::getInstance(); director->getTouchDispatcher()->addTargetedDelegate(this, 0, true); return true; }
void GalderaScene::finish() { multzoa->kalifikazioa = kalifikazioa; multzoa->currentGaldera = currentGalderaPosition; multzoa->bukatuta = 1; pSQL->updateErabiltzaileMultzoa(multzoa); BukatutaScene *scene = BukatutaScene::create(multzoa); Director *pDirector = Director::getInstance(); TransitionFade *tscene = TransitionFade::create(0.5, scene); pDirector->replaceScene(tscene); }
void GalderaScene::backButton(Ref* sender) { multzoa->kalifikazioa = kalifikazioa; multzoa->currentGaldera = currentGalderaPosition; multzoa->bukatuta = 0; pSQL->updateErabiltzaileMultzoa(multzoa); CategoryScene *scene = CategoryScene::create(); Director *pDirector = Director::getInstance(); TransitionFade *tscene = TransitionFade::create(0.5, scene); pDirector->replaceScene(tscene); }
void GridBase::beforeDraw(void) { // save projection Director *director = Director::getInstance(); _directorProjection = director->getProjection(); // 2d projection // [director setProjection:Director::Projection::_2D]; set2DProjection(); Size size = director->getWinSizeInPixels(); glViewport(0, 0, (GLsizei)(size.width), (GLsizei)(size.height) ); _grabber->beforeRender(_texture); }
void SSGun::Update(Director &director, int timePassed) { float xw = -(director.InputServiceInstance().mouseX - 360) * 1.5f / 75.0f; this->SetCenter(SSPointMake(xw, -3.5f, 10.0f)); lastShotFiredTime += timePassed; // change to if mouse down if (director.InputServiceInstance().isMouseDown && lastShotFiredTime > 300) { lastShotFiredTime = 0; SSBullet *bullet = new SSBullet(); bullet->SetCenter(this->GetCenter()); this->GetScene()->AddActor(bullet); } }
void Box2DView::onDraw(const Mat4 &transform, uint32_t flags) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); m_test->Step(&settings); m_test->m_world->DrawDebugData(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
bool loadOnlyMap(string location){ Director director; MapBuilder* mapWithoutPlayersBuilder = new MapWithoutPlayers; director.setMapBuilder(mapWithoutPlayersBuilder); if (director.constructMap(location)){ mainMap = director.getMap(); return true; } else{ return false; } }
bool Driver::loadPlayersMap(string location){ Director director; MapBuilder* mapWithPlayersBuilder = new MapWithPlayers; director.setMapBuilder(mapWithPlayersBuilder); if (director.constructMap(location)){ mainMap = director.getMap(); mainGame = director.getGame(); playersSet = true; return true; } else{ return false; } }
void ScreenSizeManager::DoInitFlexibleScreenSize(float myImageResolutionWidth, float myImageResolutionHeight) { _isInit = true; // cocos2d-x v3.0.0 이상만 지원. CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!"); Director* kDirector = Director::getInstance(); CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL"); Size kWinSize = kDirector->getWinSize(); _screenSize.width = kWinSize.width; _screenSize.height = kWinSize.height; _imageResolutionSize.width = myImageResolutionWidth; _imageResolutionSize.height = myImageResolutionHeight; float kDefaultDesignResRatio = _imageResolutionSize.width / _imageResolutionSize.height; float kScreenRatio = _screenSize.width / _screenSize.height; if ( kDefaultDesignResRatio <= kScreenRatio) { float kHeightRatio = _screenSize.height / _imageResolutionSize.height; // 폭이 넓은 경우 _imageResolutionSize.width = (int)(_screenSize.width / kHeightRatio); _isScaleHeight = true; } else { // 높이가 긴 경우 float kWidthRatio = _screenSize.width / _imageResolutionSize.width; // 폭이 넓은 경우 _imageResolutionSize.height = (int)(_screenSize.height / kWidthRatio); _isScaleHeight = false; } log("DoInitResourceSizeScreen %f %f", _imageResolutionSize.width, _imageResolutionSize.height); // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다. // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다. ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER; GLView* kGLView = kDirector->getOpenGLView(); kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy); }
bool TimeUpMenuLayer::init() { if(!LayerColor::init()) { return false; } Director* director = Director::getInstance(); Vec2 visibleOrigin = director->getVisibleOrigin(); Size visibleSize = director->getVisibleSize(); // setContentSize(visibleSize); Widget* mainMenuLayer = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/time_up_menu.json"); addChild(mainMenuLayer); mainMenuLayer->setContentSize(visibleSize); Node* mainMenu = mainMenuLayer->getChildByName("content"); mainMenu->setPositionY((visibleSize.height-mainMenu->getContentSize().height)/2); Util::registerButton(mainMenu, "tryAgain", [&](Ref* ref,Widget::TouchEventType event){ switch (event) { case cocos2d::ui::Widget::TouchEventType::ENDED: { m_gameLayer->reset(); removeFromParent(); } break; default: break; } }, "time_up_menu_try_again"); Util::registerButton(mainMenu, "toMainMenu", [=](Ref* ref,Widget::TouchEventType event){ switch (event) { case cocos2d::ui::Widget::TouchEventType::ENDED: { auto scene = MainMenuLayer::createScene(); director->replaceScene(scene); } break; default: break; } }, "pause_menu_back_to_main_menu"); Text* title = dynamic_cast<Text*>(mainMenu->getChildByName("title")); title->setString(LANG->getLang("time_up_menu_title")); return true; }
int main(int argc, char const *argv[]) { Director* director = new Director(); Builder* b1 = new ConcreteBuilder1(); Builder* b2 = new ConcreteBuilder2(); director->Constructor(b1); Product* p1 = b1->GetResult(); p1->Show(); director->Constructor(b2); Product* p2 = b2->GetResult(); p2->Show(); return 0; }
bool Layer::init() { bool bRet = false; do { Director * pDirector; CC_BREAK_IF(!(pDirector = Director::getInstance())); this->setContentSize(pDirector->getWinSize()); setTouchEnabled(false); setAccelerometerEnabled(false); // success bRet = true; } while(0); return bRet; }
void GridBase::set2DProjection() { Director *director = Director::getInstance(); Size size = director->getWinSizeInPixels(); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Mat4 orthoMatrix; Mat4::createOrthographicOffCenter(0, size.width, 0, size.height, -1, 1, &orthoMatrix); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); GL::setProjectionMatrixDirty(); }
void SceneManager::go(Scene* scene) { Layer* layer = (Layer*)scene; Director *director = Director::getInstance(); Scene *newScene = SceneManager::wrap(layer); if ( director->getRunningScene() ) { director->replaceScene(newScene); } else { director->runWithScene(newScene); } }
bool SeahorseLayer::init() { isBye = false; byePoint = 0; isHeadToLeft = true; isAttachedToDiver = false; initWithPlist(p_Seahorse, s_Seahorse); //touch Director* director = Director::getInstance(); director->getTouchDispatcher()->addTargetedDelegate(this, 0, true); return true; }
void RenderTexture::onEnd() { Director *director = Director::getInstance(); glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); // restore viewport director->setViewport(); const auto& vp = Camera::getDefaultViewport(); glViewport(vp._left, vp._bottom, vp._width, vp._height); // director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _oldProjMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _oldTransMatrix); }
void SceneManager::go(Layer* layer) { Director *director = Director::getInstance(); Scene *newScene = SceneManager::wrap(layer); if ( director->getRunningScene() ) { s_nSceneIdx++; s_nSceneIdx = s_nSceneIdx % MAX_LAYER; Director::getInstance()->replaceScene(createTransition(s_nSceneIdx, TRANSITION_DURATION, newScene)); } else { director->runWithScene(newScene); } }
int LuaEngine::executeLayerTouchesEvent(Layer* pLayer, int eventType, Set *pTouches) { TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry(); if (!pScriptHandlerEntry) return 0; int nHandler = pScriptHandlerEntry->getHandler(); if (!nHandler) return 0; switch (eventType) { case CCTOUCHBEGAN: _stack->pushString("began"); break; case CCTOUCHMOVED: _stack->pushString("moved"); break; case CCTOUCHENDED: _stack->pushString("ended"); break; case CCTOUCHCANCELLED: _stack->pushString("cancelled"); break; default: return 0; } Director* pDirector = Director::sharedDirector(); lua_State *L = _stack->getLuaState(); lua_newtable(L); int i = 1; for (SetIterator it = pTouches->begin(); it != pTouches->end(); ++it) { Touch* pTouch = (Touch*)*it; Point pt = pDirector->convertToGL(pTouch->getLocationInView()); lua_pushnumber(L, pt.x); lua_rawseti(L, -2, i++); lua_pushnumber(L, pt.y); lua_rawseti(L, -2, i++); lua_pushinteger(L, pTouch->getID()); lua_rawseti(L, -2, i++); } int ret = _stack->executeFunctionByHandler(nHandler, 2); _stack->clean(); return ret; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director Director* pDirector = Director::sharedDirector(); EGLView* pEGLView = EGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); // Set the design resolution pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); Size frameSize = pEGLView->getFrameSize(); vector<string> searchPath; // In this demo, we select resource according to the frame's height. // If the resource size is different from design resolution size, you need to set contentScaleFactor. // We use the ratio of resource's height to the height of design resolution, // this can make sure that the resource's height could fit for the height of design resolution. // if the frame's height is larger than the height of medium resource size, select large resource. if (frameSize.height > mediumResource.size.height) { searchPath.push_back(largeResource.directory); pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width)); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height > smallResource.size.height) { searchPath.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { searchPath.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // set searching path FileUtils::sharedFileUtils()->setSearchPaths(searchPath); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object Scene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); return true; }
bool MapScene::init() { if (!Scene::init()){ return false; } Director *director = Director::getInstance(); Size winSize = director->getWinSize(); Layer *mapLayer = Layer::create(); Sprite *map = Sprite::create("Map/Main_Main.png"); map->setAnchorPoint(Vec2::ZERO); mapLayer->addChild(map); Sprite *regionNormal = Sprite::create("Map/Main_flag.png"); Sprite *regionSelected = Sprite::create("Map/Main_flag.png"); regionSelected->setScale(1.2f); std::function<void(Ref *ref)> onRegionTouched = [this](Ref *ref)->void { if (_readyMenu) { delete _readyMenu; _readyMenu = nullptr; } RegionInfo regionInfo; HeroInfo heroInfo; regionInfo.stageName = "Stage1.json"; heroInfo.heroName = "normal"; _readyMenu = new ReadyMenu(regionInfo, heroInfo); Layer *readyLayer = _readyMenu->getLayer(); addChild(readyLayer); }; MenuItemSprite *regionMenuItem = MenuItemSprite::create(regionNormal, regionSelected, onRegionTouched); Menu *regionMenu = Menu::create(regionMenuItem, nullptr); regionMenu->setPosition(Vec2(700.0f, 220.0f)); mapLayer->addChild(regionMenu); ScrollView *scrollView = ScrollView::create(winSize, mapLayer); scrollView->setTouchEnabled(true); scrollView->setContentSize(map->getContentSize()); scrollView->setPosition(Vec2::ZERO); scrollView->setDirection(ScrollView::Direction::BOTH); scrollView->setBounceable(false); addChild(scrollView); return true; }
bool Scene::initWithPhysics() { bool ret = false; do { Director * director; CC_BREAK_IF( ! (director = Director::getInstance()) ); this->setContentSize(director->getWinSize()); CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::construct(*this))); // success ret = true; } while (0); return ret; }
void RenderTexture::end() { _endCommand.init(_globalZOrder); _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); Renderer *renderer = director->getRenderer(); renderer->addCommand(&_endCommand); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }