cocos2d-x 2.x 滚动视图 CCScrollView

page=0;

    winSize=CCDirector::sharedDirector()->getWinSize();

    CCLayer *layer=CCLayer::create();

    for (int i=0; i<ADJUST_SCROLLVIEW_COUNT; i++) {

        CCSprite *sprite=CCSprite::create("HelloWorld.png");

        sprite->setScale(0.5f);

        sprite->setPosition(ccp(winSize.width/2+i*winSize.width,winSize.height/2));

        layer->addChild(sprite);

    }

    layer->setContentSize(CCSizeMake(winSize.width*ADJUST_SCROLLVIEW_COUNT,winSize.height));

    char text[16]={0};

    sprintf(text, "%d",(page+1));

    label=CCLabelTTF::create(text,"Thonburi", 30);

    label->setAnchorPoint(CCPoint(0.5,0.5));

    label->setPosition(ccp(winSize.width/2,winSize.height-label->getContentSize().height));

    this->addChild(label);

    //-----------------------------------------------

    scrollView=CCScrollView::create(CCSizeMake(winSize.width,winSize.height));

    scrollView->setContainer(layer);

    scrollView->setBounceable(true);//是否开启弹性效果


    // 设置滚屏属性

    //    kCCScrollViewDirectionNone = -1,

    //    kCCScrollViewDirectionHorizontal = 0,

    //    kCCScrollViewDirectionVertical,

    //    kCCScrollViewDirectionBoth

    scrollView->setDirection(kCCScrollViewDirectionHorizontal);

    scrollView->setDelegate(this);

    

    this->addChild(scrollView);




代码下载

你可能感兴趣的:(游戏,String,xcode,音乐,语言)