Пример #1
0
//
// DelayTime
//
DelayTime* DelayTime::create(float d)
{
    DelayTime* pAction = new DelayTime();

    pAction->initWithDuration(d);
    pAction->autorelease();

    return pAction;
}
Пример #2
0
// on "init" you need to initialize your instance
bool LevelScene::init()
{
    SQLHelper *pSQLHelper = SQLHelper::getInstance();
    multzoak = pSQLHelper->queryMultzoak(kategoria->idKategoria);
    
    int numElements = (int) multzoak->size();
    
    int numPages = numElements / kGridElements;
   
    if (numPages == 0)
        numPages = 1;
    
    if (numElements % kGridElements != 0)
        numPages++;
    
    m_pButtonsArray = new Vector<Ref*>();
    
    Size screenSize = VisibleRect::getVisibleRect().size;
    
    Layer *pBglayer = Layer::create();
    pBglayer->setPosition(Vec2(VisibleRect::leftBottom().x, VisibleRect::leftBottom().y));
    pBglayer->setContentSize(screenSize);
    
    Sprite *fondo = Sprite::create("fondo.png");
    fondo->setPosition(VisibleRect::center());
    
    addChild(fondo);
    
    auto pTitle = Label::createWithTTF(kategoria->izena.c_str(), "fonts/CarterOne.ttf", 20.0f);
    pTitle->setHorizontalAlignment(TextHAlignment::CENTER);
    pTitle->setVerticalAlignment(TextVAlignment::CENTER);
    pTitle->setColor(Color3B(0, 0, 0));
    pTitle->setPosition(Vec2(screenSize.width/2, VisibleRect::top().y - 40));
    
    pBglayer->addChild(pTitle);
    
    auto pBackButton = SpriteButton::create(ImageManager::getImage("go-back"), 1.0f, CC_CALLBACK_1(LevelScene::backButton, this));
    pBackButton->setAnchorPoint(Vec2(0, 1));
    //pBackButton->setPosition(Vec2(VisibleRect::left().x, VisibleRect::top().y));
    pBackButton->setPosition(Vec2(0, VisibleRect::top().y));
    pBglayer->addChild(pBackButton);
    
    auto pScrollLayers = new Vector<Layer*>(numPages);
    
    Size gridLayerSize = Size(screenSize.width, pTitle->getPosition().y - pTitle->getContentSize().height / 2);
    
    MultzoaModel *multzoa;
    int count = 0;
    
    for (int i = 1; i <= numPages; i++) {
        
        Layer *lContainer = Layer::create();
        
        Layer *lContainerSubView = Layer::create();
        lContainerSubView->setContentSize(Size(gridLayerSize.width, gridLayerSize.height));
        
        Point layerPosition[] = {
            Vec2((gridLayerSize.width / 4) * 1, (gridLayerSize.height / 4) * 3), // up-left
            Vec2((gridLayerSize.width / 4) * 1, (gridLayerSize.height / 4) * 1), // down-left
            Vec2((gridLayerSize.width / 4) * 3, (gridLayerSize.height / 4) * 3), // up-right
            Vec2((gridLayerSize.width / 4) * 3, (gridLayerSize.height / 4) * 1)  // down-right
        };
        
        for (int j = 0; j < 4; j++) {
            if (count >= multzoak->size()) {
                break;
            }
            multzoa = (MultzoaModel*) multzoak->at(count);
            
            Layer *pAreaLayer = Layer::create();
            pAreaLayer->setContentSize(Size(gridLayerSize.width / 2, gridLayerSize.height / 2));
            pAreaLayer->setPosition(layerPosition[j]);
            pAreaLayer->setAnchorPoint(Vec2(0.5,0.5));
            pAreaLayer->setIgnoreAnchorPointForPosition(false);
            
            SpriteButton *pButton = getButton(multzoa);
            Point buttonPosition = Vec2(pAreaLayer->getContentSize().width/2, pAreaLayer->getContentSize().height/2 + 10);
            pButton->setPosition(buttonPosition);
            pButton->setAnchorPoint(Vec2(0.5f,0.5f));
            pButton->setTag(count);
            pButton->setIgnoreAnchorPointForPosition(false);
            pAreaLayer->addChild(pButton);
            
            Label *pMultzoaTitle = Label::createWithTTF(multzoa->izena.c_str(), "fonts/PT_Sans-Web-Regular.ttf", 14.0);
            pMultzoaTitle->setColor(Color3B(0, 0, 0));
            pMultzoaTitle->setContentSize(pAreaLayer->getContentSize());
            pMultzoaTitle->setPosition(Vec2(pAreaLayer->getContentSize().width/2, 30));
            pMultzoaTitle->setVerticalAlignment(TextVAlignment::CENTER);
            pMultzoaTitle->setHorizontalAlignment(TextHAlignment::CENTER);
            pAreaLayer->addChild(pMultzoaTitle);
            
            lContainerSubView->addChild(pAreaLayer);
            count++;
        }
        
        lContainer->addChild(lContainerSubView);
        pScrollLayers->pushBack(lContainer);
    }
    
    Size scollFrameSize = Director::getInstance()->getWinSize();
    pScrollLayer = ScrollLayer::nodeWithLayers(pScrollLayers, 0);
    pScrollLayer->setContentSize(scollFrameSize);
    pScrollLayer->setPosition(Vec2(0, 0));
    pScrollLayer->setPagesIndicatorPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 10));
    pScrollLayer->setDelegate(this);
    pScrollLayer->moveToPage(0);
    DelayTime *readyDelay = new DelayTime();
    readyDelay->initWithDuration(0.7f);
    FiniteTimeAction *readySequence = Sequence::create(readyDelay, NULL);
    runAction(readySequence);
    pBglayer->addChild(pScrollLayer);
    
    addChild(pBglayer);
    
	return true;
}