Example #1
0
void Game2048::initUI()
{
	//scene -> gameLayer -> root / uiNode
	LayerColor *gameLayer = LayerColor::create(Color4B(0xff, 0xff, 0xf0, 0xff));
	this->addChild(gameLayer);

	Node *root = Node::create();
	gameLayer->addChild(root);

	Node *uiNode = Node::create();
	gameLayer->addChild(uiNode);

	lblScore = Label::createWithTTF("", "fonts/Marker Felt.ttf", 24);
	lblScore->setPosition(Vec2(DISPLAY_CX, DISPLAY_HEIGHT * 4 / 5));
	uiNode->addChild(lblScore);

	//root -> bg 
	bgSize = DISPLAY_WIDTH - offsetW;

	LayerColor *bgLayer = LayerColor::create(Color4B(0xcd, 0xba, 0x96, 0xff), bgSize, bgSize);
	bgLayer->setPosition(Point(DISPLAY_CX,DISPLAY_CY));
	bgLayer->setAnchorPoint(Point(0.5, 0.5));
	bgLayer->ignoreAnchorPointForPosition(false);
	root->addChild(bgLayer);

	//NumNode
	numSize = (bgSize - offsetW) / s_row ;

	for (int i = 0; i < s_row; i++)
	{
		for (int j = 0; j < s_row; j++)
		{
			int numberX = numSize*(i+0.5) + DISPLAY_CX - bgSize/2 + offsetW/2 ;
			int numberY = numSize*(j+0.5) + DISPLAY_CY - bgSize/2 + offsetW/2;

			Node *numNode = Node::create();
			numNode->setPosition(Point(numberX, numberY));
			root->addChild(numNode);

			//bg
			LayerColor *numBg = LayerColor::create(Color4B(200, 190, 180, 0xff), numSize-offsetW/2, numSize-offsetW/2);
			numBg->setAnchorPoint(Point(0.5, 0.5));
			numBg->ignoreAnchorPointForPosition(false);
			numNode->addChild(numBg);

			//card
			cardNumbers[i][j] = 0;
			Node *cardNode = createNumCard(cardNumbers[i][j]);
			cardNodes[i][j] = cardNode;

			numNode->addChild(cardNode);
		}
	}

	randomCreateNum();
	randomCreateNum();

}
Example #2
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

	/**/
    // add "HelloWorld" splash screen"
	auto sprite = Sprite::create("bkq.png");
    // position the sprite on the center of the screen
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    // add the sprite as a child to this layer
  //  this->addChild(sprite, 0);
	sprite->setTag(1024);

	//scheduleUpdate();
	//schedule(schedule_selector(HelloWorld::updateTest), 1.0f, kRepeatForever,5.0f);
	
	/**/
	//color4b rgbA   LayerColorĬÈÏêµã0,0
	LayerColor* redLayer = LayerColor::create(Color4B(255, 0, 0, 255), visibleSize.width / 2, visibleSize.height / 2);
	redLayer->ignoreAnchorPointForPosition(false);
	redLayer->setPosition(visibleSize / 2);
	redLayer->setAnchorPoint(Vec2(0.5, 0.5));
	this->addChild(redLayer);
	LayerColor* blueLayer = LayerColor::create(Color4B(0, 0, 255, 255), visibleSize.width / 6, visibleSize.height / 6);
	blueLayer->ignoreAnchorPointForPosition(false);
	blueLayer->setAnchorPoint(Vec2(1, 1));
	redLayer->addChild(blueLayer);

	/*
	DrawNode * rect = DrawNode::create();
	addChild(rect);
	rect->setZOrder(10);
	rect->drawSolidRect(Vec2(100,100),Vec2(300,300),Color4F(1,0,0,1));

	DrawNode * rect2 = DrawNode::create();
	addChild(rect2);
	rect2->drawSolidRect(Vec2(150, 150), Vec2(350, 350), Color4F(0, 1, 0, 1));

	DrawNode * rect3 = DrawNode::create();
	addChild(rect3);
	rect3->drawSolidRect(Vec2(200, 200), Vec2(400, 400), Color4F(0, 0, 1, 1));
	*/


    return true;
}
Example #3
0
void MessageItem::init(char *msg, int time)
{
	_msg = msg;
	_time = time;
	_curTime = 0;

	Size size = Size(400, 0);

	_node = LayerRGBA::create();
	_node->retain();

	LayerColor *bg = LayerColor::create(Color4B(0x0, 0x0, 0x0, 0xaa), 20, 20);
    bg->setAnchorPoint(Point(0.5f, 0.5f));
	bg->ignoreAnchorPointForPosition(false);
	_node->addChild(bg);
	
	//Marker Felt
	auto label1 = LabelTTF::create(_msg, "Marker Felt", 20, size, 
		TextHAlignment::CENTER, 
		TextVAlignment::TOP);
	size.height = label1->getContentSize().height + 20;
	bg->setContentSize(size);

    label1->setAnchorPoint(Point(0.5f, 0.5f));
	_node->addChild(label1);

}
Example #4
0
LayerColor* GameLayer::createLayer(const Size& size, Color4B color, Vec2 position){
    LayerColor* layerColor = LayerColor::create(color, size.width, size.height);
    layerColor->setAnchorPoint(Vec2(0.5, 0.5));
    layerColor->ignoreAnchorPointForPosition(false);
    layerColor->setPosition(position);
    return layerColor;
}
Example #5
0
LayerColor* GameLayer::createBackgroundTile(float x, float y, Size size, Color4B color) {
    LayerColor* layerColor = LayerColor::create(color, size.width, size.height);
    layerColor->ignoreAnchorPointForPosition(false);
    layerColor->setAnchorPoint(Vec2(0.5, 0.5));
    layerColor->setPosition(getTilePosition(x, y));
    
    return layerColor;
}
Example #6
0
	bool SnakeLayer::init()
	{
		maximumLength = 100;
		itemsPicked = 0;
		score = 0;
		bonus = 0;
		direction = Point::ZERO;
		speed = 180;

		LayerColor* lc = LayerColor::create(Color4B(0, 0, 0, 210), PX(1.0f), PY(0.8f));
		lc->setPosition(CP(0.5f, 0.5f));
		lc->setAnchorPoint(Point(0.5f, 0.5f));
		lc->ignoreAnchorPointForPosition(false);
		addChild(lc);
		bounds = lc->getBoundingBox();

		LayerColor* scorebg = LayerColor::create(Color4B::BLACK, PX(1.0f), PY(0.1f));
		scorebg->setPosition(Point::ZERO);
		addChild(scorebg);

		addChild(lineGroup = Node::create());
		addChild(bonusGroup = Node::create());
		addChild(itemGroup = Node::create());

		LineNode* line = LineNode::create(CP(0.5f, 0.5f), CP(0.5f, 0.5f));
		lineGroup->addChild(line);

		schedule(schedule_selector(SnakeLayer::considerSpawningBonus), 5.0f);
		scheduleUpdate();

		lblScore = Label::createWithTTF(LS("ScoreColon") + " 0", NORMAL_TTF, 42.0f);
		lblScore->setColor(Color3B::WHITE);
		lblScore->setPosition(CP(0.5f, 0.05f));
		//lblScore->enableGlow(Color4B::BLACK);
		//lblScore->enableShadow(Color4B::BLACK, Size::ZERO, 4);
		addChild(lblScore);

		string instruction = LS("SNAKE_INSTRUCTIONS");
		lblInstruction = Label::createWithTTF(instruction, NORMAL_TTF, 48.0f);
		lblInstruction->setPosition(CP(0.5f, 0.5f));
		lblInstruction->setHorizontalAlignment(TextHAlignment::CENTER);
		lblInstruction->setColor(Color3B::WHITE);
		lblInstruction->enableGlow(Color4B::RED);
		lblInstruction->runAction(RepeatForever::create(
			Sequence::createWithTwoActions(ScaleTo::create(1.0f, 1.1f),
			ScaleTo::create(1.0f, 1.0f))));
		addChild(lblInstruction);
		instructionVisible = true;

		return true;
	}
Example #7
0
void Ajustes::initTitulo(){
    LayerColor *capaPosTitulo = LayerColor::create(Color4B(23, 70, 108, 210), cuadroJuego->getContentSize().width-(espacioBordesCuadro*escala*2), 200*escala);
    capaPosTitulo->setAnchorPoint(Vec2(0,1));
    capaPosTitulo->setPosition(anchoLateralCE+(espacioSuperiorBtAtras*escala),visibleSize.height-(200*escala)-(espacioSuperiorBtAtras*escala));
    capaPosTitulo->setZOrder(1);
    this->addChild(capaPosTitulo);
    

    tituloEscena = CCLabelTTF::create(LanguageManager::getInstance()->getString("AjustesLbTitulo"), "HVD_Comic_Serif_Pro.ttf", 130*escala,CCSizeMake(anchoNoLateralCE, capaPosTitulo->getContentSize().height), TextHAlignment::CENTER);
    tituloEscena->setColor(Color3B(216,254,51));
    tituloEscena->setVerticalAlignment(TextVAlignment::CENTER);
    tituloEscena->setAnchorPoint(Vec2(0, 0));
    tituloEscena->setPosition(anchoLateralCE,capaPosTitulo->getPositionY());
    tituloEscena->setZOrder(10);
    this->addChild(tituloEscena, 1);
    tituloEscena->retain();

}
Example #8
0
// on "init" you need to initialize your instance
bool Bug914Layer::init()
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if (BugsTestBaseLayer::init())
    {
        auto listener = EventListenerTouchAllAtOnce::create();
        listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
        listener->onTouchesMoved = CC_CALLBACK_2(Bug914Layer::onTouchesMoved, this);
        _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
        
        // ask director the the window size
        auto size = Director::getInstance()->getWinSize();
        LayerColor *layer;
        for( int i=0;i < 5;i++)
        {
            layer = LayerColor::create(Color4B(i*20, i*20, i*20,255));
            layer->setContentSize(Size(i*100, i*100));
            layer->setPosition(Vec2(size.width/2, size.height/2));
            layer->setAnchorPoint(Vec2(0.5f, 0.5f));
            layer->ignoreAnchorPointForPosition(false);
            addChild(layer, -1-i);
        }

        // create and initialize a Label
        auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 64.0f);
        auto item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));

        auto menu = Menu::create(item1, nullptr);
        menu->alignItemsVertically();
        menu->setPosition(Vec2(size.width/2, 100));
        addChild(menu);

        // position the label on the center of the screen
        label->setPosition(Vec2( size.width /2 , size.height/2 ));

        // add the label as a child to this Layer
        addChild(label);
        return true;
    }
    return false;
}
// on "init" you need to initialize your instance
bool MainLoadingScene::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    
    LayerColor *layer = LayerColor::create();
    layer->initWithColor(Color4B(255, 255, 255, 255), VisibleRect::right().x , VisibleRect::top().y);
    layer->setPosition(VisibleRect::center());
    layer->setAnchorPoint(Vec2(0.5f, 0.5f));
    layer->setIgnoreAnchorPointForPosition(false);
    this->addChild(layer, 0);
    
    Sprite *fondo = Sprite::create("fondo.png");
    fondo->setPosition(VisibleRect::center());
    this->addChild(fondo);

    
    Sprite *sprite = Sprite::create("logo.png");
    sprite->setPosition(VisibleRect::center());
    this->addChild(sprite);
    
    Label *progress = Label::createWithTTF ("Kargatzen ari da.\nMesedez, minutu pare bat itxaron.", "fonts/PT_Sans-Web-Regular.ttf", 10);
    progress->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 12));
    progress->setAnchorPoint(Vec2(0.5,0.5));
    progress->setColor(Color3B(0,0,0));
    addChild(progress);
    
    loading = Sprite::create("loading.png");
    loading->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + progress->getContentSize().height + loading->getContentSize().height / 2));
    addChild(loading);
    
    ActionInterval* rotate = RotateBy::create(5.0f, 360.0f);
    RepeatForever *repeat = RepeatForever::create(rotate);
    loading->runAction(repeat);
    
	return true;
}
// on "init" you need to initialize your instance
bool Bug914Layer::init()
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if (BugsTestBaseLayer::init())
    {
        setTouchEnabled(true);
        // ask director the the window size
        Size size = Director::getInstance()->getWinSize();
        LayerColor *layer;
        for( int i=0;i < 5;i++)
        {
            layer = LayerColor::create(Color4B(i*20, i*20, i*20,255));
            layer->setContentSize(Size(i*100, i*100));
            layer->setPosition(Point(size.width/2, size.height/2));
            layer->setAnchorPoint(Point(0.5f, 0.5f));
            layer->ignoreAnchorPointForPosition(false);
            addChild(layer, -1-i);
        }

        // create and initialize a Label
        LabelTTF *label = LabelTTF::create("Hello World", "Marker Felt", 64);
        MenuItem *item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));

        Menu *menu = Menu::create(item1, NULL);
        menu->alignItemsVertically();
        menu->setPosition(Point(size.width/2, 100));
        addChild(menu);

        // position the label on the center of the screen
        label->setPosition(Point( size.width /2 , size.height/2 ));

        // add the label as a child to this Layer
        addChild(label);
        return true;
    }
    return false;
}
Example #11
0
TableViewCell* Ranking::tableCellAtIndex(TableView *table, ssize_t idx) {
    RankingData *rankingData = _rankingData.at(idx);
    
    table->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
    TableViewCell *cell = table->dequeueCell();
    
    if (!cell) {
        cell = new TableViewCell();
        cell->autorelease();
    }
    cell->removeAllChildren();
    
    auto colorLayer = LayerColor::create();
    colorLayer->setAnchorPoint(Point::ZERO);
    colorLayer->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, TableViewItemHeightValue.asFloat()));
    colorLayer->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width, 0));
    cell->addChild(colorLayer);
    
    string numberRanking;
    ostringstream convert2;
    convert2 << idx + 1;
    numberRanking = convert2.str();
    
    auto padding = 25;
    auto number = Label::createWithTTF(numberRanking, MainRegularFont, 60);
    number->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels - padding, TableViewItemHeightValue.asFloat()));
    number->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels);
    number->setHeight(TableViewItemHeightValue.asFloat());
    number->setVerticalAlignment(TextVAlignment::CENTER);
    number->setHorizontalAlignment(TextHAlignment::LEFT);
    number->setAnchorPoint(Point::ZERO);
    if (idx == 0) {
        number->setTextColor(IkasPurple);
    } else {
        number->setTextColor(IkasPurpleLight);
    }
    number->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width + padding/ _totalLabels, 0));
    cell->addChild(number);
    
    
    auto name = Label::createWithTTF(rankingData->getuser(), MainRegularFont, 60);
    name->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels, TableViewItemHeightValue.asFloat()));
    name->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels);
    name->setHeight(TableViewItemHeightValue.asFloat());
    name->setVerticalAlignment(TextVAlignment::CENTER);
    name->setHorizontalAlignment(TextHAlignment::CENTER);
    name->setAnchorPoint(Point::ZERO);
    if (idx == 0) {
        name->setTextColor(IkasPurple);
    } else {
        name->setTextColor(IkasPurpleLight);
    }
    name->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width / _totalLabels, 0));
    cell->addChild(name);
    
    string points;
    ostringstream convert;
    convert << rankingData->getpoints();
    points = convert.str();
    
    auto pointsLabel = Label::createWithTTF(points, MainRegularFont, 60);
    pointsLabel->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels, TableViewItemHeightValue.asFloat()));
    pointsLabel->setHeight(TableViewItemHeightValue.asFloat());
    pointsLabel->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels);
    pointsLabel->setVerticalAlignment(TextVAlignment::CENTER);
    pointsLabel->setHorizontalAlignment(TextHAlignment::CENTER);
    pointsLabel->setAnchorPoint(Point::ZERO);
    if (idx == 0) {
        pointsLabel->setTextColor(IkasPurple);
    } else {
        pointsLabel->setTextColor(IkasPurpleLight);
    }
    pointsLabel->setPosition(Vec2(1 * _tableViewRanking->getBoundingBox().size.width / _totalLabels, 0));
    cell->addChild(pointsLabel);
//    
//    if (idx % 2 == 0) {
//        number->setTextColor(IkasWhite);
//        name->setTextColor(IkasWhite);
//        pointsLabel->setTextColor(IkasWhite);
//        colorLayer->setColor(Color3B(IkasRed));
//        colorLayer->setOpacity(60);
//    } else {
//        number->setTextColor(IkasRed);
//        name->setTextColor(IkasRed);
//        pointsLabel->setTextColor(IkasRed);
//        colorLayer->setColor(Color3B(IkasWhite));
//        colorLayer->setOpacity(0);
//    }
    
    LayerColor *topSeparator;
    if (idx % 2 == 0) {
        topSeparator = LayerColor::create(IkasPurpleLight);
    } else {
        topSeparator = LayerColor::create(IkasPurpleLightAlpha);
    }
    topSeparator->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, 2));
    topSeparator->setPosition(Vec2(0, TableViewItemHeightValue.asFloat() - 4));
    topSeparator->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
    cell->addChild(topSeparator);

    
    if (idx == _rankingData.size() - 1) {
        if (idx % 2 != 0) {
            topSeparator = LayerColor::create(IkasPurpleLight);
        } else {
            topSeparator = LayerColor::create(IkasPurpleLightAlpha);
        }
        topSeparator->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, 2));
        topSeparator->setPosition(Vec2(0, 0));
        topSeparator->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
        cell->addChild(topSeparator);
    }
    return cell;
}
void FriendListScene::buildScene()
{
    _friendDictionary.clear();
    _friendList.clear();
    _tableView = NULL;
    _downloadCount = 0;
    
    const char* headerString = "";
    
    switch (_selectedFriendCircle)
    {
        case ALL_FRIENDS:
            headerString = "All Friends";
            break;
        
        case INSTALLED_ONLY:
            headerString = "Friends Playing Game";
            break;
            
        case NON_PLAYING_ONLY:
            headerString = "Friends not Playing Game";
            break;
            
        case MY_DEVICE_ONLY:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
            headerString = "Friends playing on iOS Device";
#else
            headerString = "Friends playing on Android Device";
#endif
        default:
            break;
    }
    
    //_friendList = CCArray::createWithCapacity(5);
    //_friendList->retain();
    CCLOG("ALL Request count = %lu", _friendList.size());
    
    // Add background layers to the scene.
    LayerColor *bg = LayerColor::create(Color4B(255, 255, 255, 255), AppDelegate::SCREEN_WIDTH, AppDelegate::SCREEN_HEIGHT);
    this->addChild(bg);
    
    LayerColor *secondBG = LayerColor::create(Color4B(95, 95, 95, 255),
                                                  AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f),
                                                  AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(20.0f));
    
    secondBG->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10.0f)));
    this->addChild(secondBG);
    
    // Set the table header.
    LayerColor *header = LayerColor::create(Color4B(66, 66, 66, 255),
                                                AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f),
                                                SCALED_VALUE(100.0f));
    header->setAnchorPoint(Point(0, 0));
    header->setPosition(Point(SCALED_VALUE(10.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(110.0f)));
    this->addChild(header);
    
    // Set the header text.
    auto headerText = LabelTTF::create(headerString, "Arial", SCALED_VALUE(40.0f));
    headerText->setAnchorPoint(Point(0.0f, 0.5f));
    header->addChild(headerText);
    headerText->setPositionX(SCALED_VALUE(28.0f));
    headerText->setPositionY(header->getContentSize().height/2);
    
    // Add back button go back to previous scene
    MenuItemImage *backButton = MenuItemImage::create();
    backButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_nrl"));
    backButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_prd"));
    
    backButton->setCallback(CC_CALLBACK_1(FriendListScene::backButtonPressed, this));

    backButton->setAnchorPoint(Point(1.0f, 0.5));
    Menu* backMenu = Menu::create(backButton, NULL);
    header->addChild(backMenu);
    backMenu->setPositionX(header->getContentSize().width - SCALED_VALUE(20.0f));
    backMenu->setPositionY(header->getContentSize().height/2);
    
    
    // Create the table view.
    float tableHeight = bg->getContentSize().height - secondBG->getPositionY() - (header->getContentSize().height) - SCALED_VALUE(10);
    _tableView = TableView::create(this, Size(secondBG->getContentSize().width, tableHeight));
    _tableView->setAnchorPoint(Point(0, 0.0));
    _tableView->setDirection(ScrollView::Direction::VERTICAL);
    _tableView->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10)));
    _tableView->setDelegate(this);
    this->addChild(_tableView);
}