Example #1
0
bool GameNext::init()
{
    //////////////////////////////
    // 1. super init first
    if (!Scene::init())
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////

    
    if(game_round<=9)
    {
        gr_pic = "0" + Value(game_round).asString();
    }else if(game_round>=10)
    {
        gr_pic = Value(game_round).asString();
    }
    
    if((game_level-1)<=9)
    {
        gl_pic = "0" + Value(game_level-1).asString();
    }else if((game_level-1)>=10)
    {
        gl_pic = Value(game_level-1).asString();
    }
    
    
    //被弄成灰色的截图
    auto ac = Sprite::create(picNext);
    ac->setAnchorPoint(Vec2(0,0));
    ac->setPosition(Vec2(0,0));
    ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例
    ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY());
    this->addChild(ac,100);
    
    
    //半透明层,在截图之上
    LayerColor* layerColor = CCLayerColor::create();
    layerColor->setColor(cocos2d::Color3B(0, 0, 0));
    layerColor->setOpacity(150);
    layerColor->setContentSize(Size(visibleSize.width, visibleSize.height));
    this->addChild(layerColor,101);
    
    
    //next小方块的背景
    auto gameover = Sprite::create("setting/gamenext.png");
    gameover->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height/2));
    this->addChild(gameover,102);
    
    
    scheduleUpdate();
    
    return true;
    
}
Example #2
0
bool GameOver::init()
{
    //////////////////////////////
    // 1. super init first
    if (!Scene::init())
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////
   
    
    
    
    auto ac = Sprite::create(picOver);
    ac->setAnchorPoint(Vec2(0,0));
    ac->setPosition(Vec2(0,0));
    ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例
    ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY());
    
    this->addChild(ac,100);
    
    
    
    
    //半透明层
    
    LayerColor* layerColor = CCLayerColor::create();
    
    layerColor->setColor(cocos2d::Color3B(0, 0, 0));
    
    layerColor->setOpacity(150);
    
    layerColor->setContentSize(Size(visibleSize.width, visibleSize.height));
    
    this->addChild(layerColor,101);
    
    
    auto gameover = Sprite::create("setting/gameover.png");
    //gameover->setAnchorPoint(Vec2(0,0));
    gameover->setPosition(Vec2(origin.x + visibleSize.width/2,
                               origin.y + visibleSize.height/2));
    this->addChild(gameover,102);
    

    
    scheduleUpdate();
    
    return true;
    
}
Example #3
0
bool GameWinLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::sharedDirector()->getVisibleSize();

	// finish layer
	LayerColor* layerColor = LayerColor::create();
	layerColor->setColor(Color3B(0, 0, 0));
	layerColor->setOpacity(150);
	layerColor->setContentSize(Size(visibleSize.width, visibleSize.height));
	this->addChild(layerColor, 1);

	return true;
}
Example #4
0
void GameOverDialog::onEnter() {
    Node::onEnter();

    Size visibleSize = Director::getInstance()->getVisibleSize();
    // this->setContentSize(visibleSize);

    LayerColor *background = LayerColor::create(Color4B(0, 0, 0, 178));
    this->addChild(background);
    // background->setContentSize(visibleSize);

    // TODO: We should decide winner in the game scene
    std::string filename = _playerLifePoint == _opponentLifePoint
                               ? "labelDraw.png"
                               : (_playerLifePoint > _opponentLifePoint ? "labelYouWin.png" : "labelYouLose.png");
    Sprite *title = Sprite::create(filename);
    title->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP);
    title->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.9f));

    std::stringstream ss;
    ss << _playerLifePoint * 100 / INITIAL_PLAYER_LIFE << "% - " << _opponentLifePoint * 100 / INITIAL_PLAYER_LIFE
       << "%";
    // TODO: Do not use magic number
    auto scoreLabel = ui::Text::create(ss.str(), FONT_DIGIT, 96);
    scoreLabel->setAnchorPoint(Vec2(0.5f, 0.5f));
    scoreLabel->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.5f));
    scoreLabel->setColor(Color3B::WHITE);

    _button = ui::Button::create();
    _button->loadTextures("buttonOk.png", "buttonOkPressed.png");
    _button->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
    _button->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.1f));
    _button->addTouchEventListener(CC_CALLBACK_2(GameOverDialog::buttonPressed, this));

    this->addChild(title);
    this->addChild(scoreLabel);
    this->addChild(_button);

    auto action = cocos2d::FadeTo::create(0.1, 178);
    background->setOpacity(0);
    background->runAction(action);
}