Exemple #1
0
bool LoadingLayer::init()
{
    if(!LayerColor::init())
        return false;
    
    //Set the background color
    LoadingLayer::setColor(Color3B::WHITE);
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    Vec2 centerPoint = Utils::Utils::getCentralPoint(visibleSize, origin);
    
    //Load a planet sprite to show while the game loads
    Sprite3D* sprPlanet = Sprite3D::create("3d/meshes/MarsPlanet.obj", "3d/textures/MarsMap.jpg");
    sprPlanet->setPosition(centerPoint);
    Utils::Utils::setScale3D(10, sprPlanet);
    sprPlanet->runAction(RepeatForever::create(RotateBy::create(3,Vec3(0,360,0))));
    
    //Load the sprite with "LOADING..." string while the game loads
    Text* loadingText = Text::create("LOADING...", DEFAULT_FONT, 34);
    loadingText->setPosition(Vec2(sprPlanet->getPositionX(), SCREEN_FRAME_OFFSET));
    
    //Add elements as layer children
    addChild(sprPlanet);
    addChild(loadingText);
    
    return true;
}
void	MainScene::update( float delta )
{
	Size visibleSize = Director::getInstance()->getVisibleSize();

	/*
	if( _inputLayer->isKeyboradPushDown( KEY_CODE::KEY_ENTER ) == true ) 
	{
		log( "enter push" );
	}

	if( _inputLayer->isKeyboradPushDown( KEY_CODE::KEY_ESCAPE ) == true ) 
	{
		log( "escape push" );
	}
*/

	Sprite3D* sprite = FileLoadManager::getInstance()->getSprite3D( _modelArray.size() );
	if( sprite != nullptr )
	{
		sprite->setPosition( visibleSize.width * 0.5f, visibleSize.height * 0.5f );
		sprite->setScale( 300.0f );
		addChild( sprite );
		_modelArray.pushBack( sprite );
	}

	
	if( _selectModel != nullptr )
	{
		_selectModel->setScale( _selectModel->getScale() + _inputLayer->getMouseScroll() * 2.0f );
		_selectModel->setPosition( CCPoint( _inputLayer->getMousePosition().x, _inputLayer->getMousePosition().y - (_selectModel->getContentSize().height * _selectModel->getScale()) * 0.5f ));
	}

	if( _inputLayer->isMousePush( InputLayer::MouseFlags::LEFT_PUSH_FlAG ) == true && _selectModel == nullptr)
	{
		for( int i = 0; i < (int)_modelArray.size(); i++ )
		{
			auto rect = _modelArray.at( i )->getBoundingBox();
			if( rect.containsPoint( _inputLayer->getMousePosition() ) == true )
			{
				log( "Model Push" );
				_selectModel = _modelArray.at( i );
			}
		}
	}
	else
	{
		_selectModel = nullptr;
	}
}