void SceneManager::changeScene( EnumSceneType enScenType, bool isTrans, float time ) { Scene* pScene = getSceneByType(enScenType); if(pScene == NULL) { return; } //TextureCache::sharedTextureCache()->removeUnusedTextures(); Director* pDirector = Director::getInstance(); Scene* curScene = pDirector->getRunningScene(); if(curScene == NULL) { pDirector->runWithScene(pScene); } else { if(isTrans) { pDirector->replaceScene(TransitionFade::create(time, pScene)); } else { pDirector->replaceScene(pScene); } } }
bool CGameSceneManager::go(SCENE_TYPE st) { Scene* scene = nullptr; switch (st) { case ST_LOGIN: { CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance()); scene = pReader->createSceneWithNodeGraphFromFile("login_layer.ccbi"); delete pReader; break; } case ST_LOBBY: { CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance()); scene = pReader->createSceneWithNodeGraphFromFile("lobby_layer.ccbi"); delete pReader; break; } case ST_FORMATION: { scene = Scene::create(); scene->addChild(CFormationLayer::create()); break; } case ST_BATTLE_FIELD: { scene = Scene::create(); scene->addChild(CBattleFieldLayer::create()); // call init in create() break; } case ST_SETTINGS: break; case ST_HOME: { CCBReader* pReader = new CCBReader(NodeLoaderLibrary::getInstance()); scene = pReader->createSceneWithNodeGraphFromFile("home_layer.ccbi"); delete pReader; break; } default: break; } if (scene) { Director* pDirector = Director::getInstance(); if (pDirector->getRunningScene()) { TransitionFade* trans = TransitionFade::create(.2f, scene, Color3B(255, 255, 255)); pDirector->replaceScene(trans); } else { pDirector->runWithScene(scene); } } return true; }
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); } }
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); } }
void handle_signal(int signal) { static int internal_state = 0; ScriptingCore* sc = ScriptingCore::getInstance(); // should start everything back Director* director = Director::getInstance(); if (director->getRunningScene()) { director->popToRootScene(); } else { PoolManager::sharedPoolManager()->finalize(); if (internal_state == 0) { //sc->dumpRoot(NULL, 0, NULL); sc->start(); internal_state = 1; } else { sc->runScript("hello.js"); internal_state = 0; } } }
bool CGameSceneManager::go(SCENE_TYPE st) { Scene* scene = nullptr; switch (st) { case ST_LOGIN: { scene = CCBReadHelper::readScene("login_layer.ccbi"); break; } case ST_LOBBY: { scene = CCBReadHelper::readScene("lobby_layer.ccbi"); break; } case ST_MATCH: { scene = CCBReadHelper::readScene("pitch_layer.ccbi"); break; } default: break; } if (scene) { Director* pDirector = Director::getInstance(); if (pDirector->getRunningScene()) { TransitionFade* trans = TransitionFade::create(.2f, scene, Color3B(255, 255, 255)); pDirector->replaceScene(trans); } else { pDirector->runWithScene(scene); } } return true; }
void MeshCommand::setLightUniforms() { Director *director = Director::getInstance(); auto scene = director->getRunningScene(); const auto& conf = Configuration::getInstance(); int maxDirLight = conf->getMaxSupportDirLightInShader(); int maxPointLight = conf->getMaxSupportPointLightInShader(); int maxSpotLight = conf->getMaxSupportSpotLightInShader(); auto &lights = scene->getLights(); auto glProgram = _glProgramState->getGLProgram(); if (_glProgramState->getVertexAttribsFlags() & (1 << GLProgram::VERTEX_ATTRIB_NORMAL)) { resetLightUniformValues(); GLint enabledDirLightNum = 0; GLint enabledPointLightNum = 0; GLint enabledSpotLightNum = 0; Vec3 ambientColor; for (const auto& light : lights) { bool useLight = light->isEnabled() && ((unsigned int)light->getLightFlag() & _lightMask); if (useLight) { float intensity = light->getIntensity(); switch (light->getLightType()) { case LightType::DIRECTIONAL: { if(enabledDirLightNum < maxDirLight) { auto dirLight = static_cast<DirectionLight *>(light); Vec3 dir = dirLight->getDirectionInWorld(); dir.normalize(); const Color3B &col = dirLight->getDisplayedColor(); s_dirLightUniformColorValues[enabledDirLightNum] = Vec3(col.r / 255.0f * intensity, col.g / 255.0f * intensity, col.b / 255.0f * intensity); s_dirLightUniformDirValues[enabledDirLightNum] = dir; ++enabledDirLightNum; } } break; case LightType::POINT: { if(enabledPointLightNum < maxPointLight) { auto pointLight = static_cast<PointLight *>(light); Mat4 mat= pointLight->getNodeToWorldTransform(); const Color3B &col = pointLight->getDisplayedColor(); s_pointLightUniformColorValues[enabledPointLightNum] = Vec3(col.r / 255.0f * intensity, col.g / 255.0f * intensity, col.b / 255.0f * intensity); s_pointLightUniformPositionValues[enabledPointLightNum] = Vec3(mat.m[12], mat.m[13], mat.m[14]); s_pointLightUniformRangeInverseValues[enabledPointLightNum] = 1.0f / pointLight->getRange(); ++enabledPointLightNum; } } break; case LightType::SPOT: { if(enabledSpotLightNum < maxSpotLight) { auto spotLight = static_cast<SpotLight *>(light); Vec3 dir = spotLight->getDirectionInWorld(); dir.normalize(); Mat4 mat= light->getNodeToWorldTransform(); const Color3B &col = spotLight->getDisplayedColor(); s_spotLightUniformColorValues[enabledSpotLightNum] = Vec3(col.r / 255.0f * intensity, col.g / 255.0f * intensity, col.b / 255.0f * intensity); s_spotLightUniformPositionValues[enabledSpotLightNum] = Vec3(mat.m[12], mat.m[13], mat.m[14]); s_spotLightUniformDirValues[enabledSpotLightNum] = dir; s_spotLightUniformInnerAngleCosValues[enabledSpotLightNum] = spotLight->getCosInnerAngle(); s_spotLightUniformOuterAngleCosValues[enabledSpotLightNum] = spotLight->getCosOuterAngle(); s_spotLightUniformRangeInverseValues[enabledSpotLightNum] = 1.0f / spotLight->getRange(); ++enabledSpotLightNum; } } break; case LightType::AMBIENT: { auto ambLight = static_cast<AmbientLight *>(light); const Color3B &col = ambLight->getDisplayedColor(); ambientColor += Vec3(col.r / 255.0f * intensity, col.g / 255.0f * intensity, col.b / 255.0f * intensity); } break; default: break; } } } if (0 < maxDirLight) { glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_dirLightUniformColorName), (GLfloat*)(&s_dirLightUniformColorValues[0]), (unsigned int)s_dirLightUniformColorValues.size()); glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_dirLightUniformDirName), (GLfloat*)(&s_dirLightUniformDirValues[0]), (unsigned int)s_dirLightUniformDirValues.size()); } if (0 < maxPointLight) { glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_pointLightUniformColorName), (GLfloat*)(&s_pointLightUniformColorValues[0]), (unsigned int)s_pointLightUniformColorValues.size()); glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_pointLightUniformPositionName), (GLfloat*)(&s_pointLightUniformPositionValues[0]), (unsigned int)s_pointLightUniformPositionValues.size()); glProgram->setUniformLocationWith1fv((GLint)glProgram->getUniformLocationForName(s_pointLightUniformRangeInverseName), (GLfloat*)(&s_pointLightUniformRangeInverseValues[0]), (unsigned int)s_pointLightUniformRangeInverseValues.size()); } if (0 < maxSpotLight) { glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformColorName), (GLfloat*)(&s_spotLightUniformColorValues[0]), (unsigned int)s_spotLightUniformColorValues.size()); glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformPositionName), (GLfloat*)(&s_spotLightUniformPositionValues[0]), (unsigned int)s_spotLightUniformPositionValues.size()); glProgram->setUniformLocationWith3fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformDirName), (GLfloat*)(&s_spotLightUniformDirValues[0]), (unsigned int)s_spotLightUniformDirValues.size()); glProgram->setUniformLocationWith1fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformInnerAngleCosName), (GLfloat*)(&s_spotLightUniformInnerAngleCosValues[0]), (unsigned int)s_spotLightUniformInnerAngleCosValues.size()); glProgram->setUniformLocationWith1fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformOuterAngleCosName), (GLfloat*)(&s_spotLightUniformOuterAngleCosValues[0]), (unsigned int)s_spotLightUniformOuterAngleCosValues.size()); glProgram->setUniformLocationWith1fv((GLint)glProgram->getUniformLocationForName(s_spotLightUniformRangeInverseName), (GLfloat*)(&s_spotLightUniformRangeInverseValues[0]), (unsigned int)s_spotLightUniformRangeInverseValues.size()); } glProgram->setUniformLocationWith3f(glProgram->getUniformLocationForName(s_ambientLightUniformColorName), ambientColor.x, ambientColor.y, ambientColor.z); } else // normal does not exist { Vec3 ambient(0.0f, 0.0f, 0.0f); bool hasAmbient; for (const auto& light : lights) { if (light->getLightType() == LightType::AMBIENT) { bool useLight = light->isEnabled() && ((unsigned int)light->getLightFlag() & _lightMask); if (useLight) { hasAmbient = true; const Color3B &col = light->getDisplayedColor(); ambient.x += col.r * light->getIntensity(); ambient.y += col.g * light->getIntensity(); ambient.z += col.b * light->getIntensity(); } } } if (hasAmbient) { ambient.x /= 255.f; ambient.y /= 255.f; ambient.z /= 255.f; } glProgram->setUniformLocationWith4f(glProgram->getUniformLocationForName("u_color"), _displayColor.x * ambient.x, _displayColor.y * ambient.y, _displayColor.z * ambient.z, _displayColor.w); } }
Scene* BattleArena::createScene() { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // some upfront items that we need // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Director* dirs = Director::getInstance(); Size visibleSize = dirs->getVisibleSize(); Vec2 origin = dirs->getVisibleOrigin(); Size playingSize = Size(visibleSize.width, visibleSize.height - (visibleSize.height/8)); // actual playing size to work with // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a scene // 'scene' is an autorelease object // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scene* scene = Scene::create(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold non-sprites. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Node* nodeItems = Node::create(); nodeItems->setName("nodeItems"); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create a node to hold menu // create a menu // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Node* menuNode = Node::create(); menuNode->setName("menuNode"); int index = 2; MenuItemFont* menuItem3 = MenuItemFont::create("Summon Pikachu"); menuItem3->setFontNameObj("fonts/Marker Felt.ttf"); menuItem3->setFontSizeObj(32); menuItem3->setName("summon_pikachu"); menuItem3->setVisible(true); menuItem3->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2).x, (Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height).y - (index) * 40)); menuItem3->setCallback([&](cocos2d::Ref *sender) { Director* dirs = Director::getInstance(); Scene* runningScene = dirs->getRunningScene(); SpriteFrameCache* spritecache = SpriteFrameCache::getInstance(); spritecache->addSpriteFramesWithFile("learning/PIKACHU.plist"); Sprite* newSprite = Sprite::createWithSpriteFrameName("0.gif"); int xRandom = random(0, int(dirs->getVisibleSize().width)); int yRandom = random(246, 266); newSprite->setPosition(xRandom, yRandom); newSprite->setName("sprite3"); newSprite->setAnchorPoint(Vec2(0.5,0.5)); runningScene->addChild(newSprite,1); Vector<SpriteFrame*> animFrames; int frames = 112; animFrames.reserve(frames); char gif[8] = {0}; for(int index_frames = 0 ; index_frames < frames ; index_frames++){ sprintf(gif, "%d.gif", index_frames); animFrames.pushBack(spritecache->getSpriteFrameByName(gif)); } // create the animation out of the frames Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.05f); Animate* animate = Animate::create(animation); // run it and repeat it forever newSprite->runAction(RepeatForever::create(animate)); }); Menu* menu = Menu::create(menuItem3, NULL); menu->setName("menu"); menuNode->addChild(menu, 1); menu->setPosition(Vec2::ZERO); scene->addChild(menuNode, 2); // return the scene return scene; }