jewelnero.blogg.se

Alignitemsverticallywithpadding example ccmenu
Alignitemsverticallywithpadding example ccmenu





alignitemsverticallywithpadding example ccmenu
  1. #Alignitemsverticallywithpadding example ccmenu full
  2. #Alignitemsverticallywithpadding example ccmenu code

The entire scrollview content should layout like this:Īnd I expect when first initialized, the green sprite will be shown full screen (my view is 960x1280) and I’ll be able to scroll my moving up to see the pink sprite on the bottom. I am using cocos2d-x-2.2, including its CCScrollView. I still have problems in understanding and would like to clarify. ScrollView~~>setContentOffset(ccp(0.f, (winSize.height-scrollContainerHeight*1.05f)), false) Pre-set it to the value CCScrollView::minContainerOffset will return when it’s scrolled to the top The container also gets positioned relative to that and goes Y-up. ScrollContainer~~>setAnchorPoint // CCScrollView does this too when it’s set as the container.ĬCSprite tallContentA = CCSprite::create ĬCSprite *tallContentB = CCSprite::create įloat scrollContainerHeight = tallContentA~~>getContentSize.height + tallContentB~~>getContentSize.height ĬCScrollView scrollView = CCScrollView::create

#Alignitemsverticallywithpadding example ccmenu code

This will give the expected results/behavior.Ī more complete example is in the edited code below.ĬCSize winSize = CCDirector::sharedDirector~~>getWinSize ĬCLayer* scrollContainer = CCLayer::create // Container for the scroll view To see the container scrolled to the top to begin with (what you’d expect when working in window coordinates), set the content offset accordingly (immediately after setting it up). Imagine the container’s anchor point moves inside it. The gray rectangle (left, bottom) shows the valid region for scrolling the container. This is the state or the coordinates to”think in" when setting up and positioning the child elements and container.

alignitemsverticallywithpadding example ccmenu

The (attached) diagram shows the state of the scrollview and the container when they’re created/initialized. When you scroll down (move/pull the content upwards to see content below the cut/clip), you see the content below the bottom edge of the screen but it bounces back the moment you let go of the touch/drag because maxContainerOffset` returns (0, 0) and you’ve just tried to move to a positive content offset. Also, keep in mind the scroll view’s positioning and thecontainer are anchored (CCNode::setAnchorPoint ) to (left, bottom). The answer lies in and CCScrollView::maxContainerOffset CCScrollView works in *OpenGL coordinates* (as opposed *window coordinates*) - values are relative to (left, bottom) with positive Y axis going upwards.

alignitemsverticallywithpadding example ccmenu

Refer: “cocos2dx/extensions/GUI/CCScrollView/CCScrollView.cpp”: Sorry for the late answer and once again thank you. ScrollView->setDirection( CCScrollViewDirectionVertical ) ScrollView->setContentOffset( ccp( 0, layer->getContentSize().height ) ) ScrollView->setContentSize( CCSizeMake( layer->getContentSize().width, winSize.height )) Layer->setContentSize( CCSizeMake( winSize.width, winSize.height*4 ) ) Menu->setPosition( ccp(winSize.width/2, winSize.height/2 ) ) Menu->alignItemsVerticallyWithPadding( 0 ) How are you adding the elements to the scrollable view?ĬCMenuItemSprite *menuHeader = CCMenuItemSprite::create( header, header, this, menu_selector(Menu::menu1Callback)) ĬCMenuItemSprite *menuGame1 = CCMenuItemSprite::create( game1, game1, this, menu_selector(Menu::menu1Callback)) ĬCMenuItemSprite *menuGame2 = CCMenuItemSprite::create( game2, game2, this, menu_selector(Menu::menu1Callback)) ĬCMenuItemSprite *menuFooter = CCMenuItemSprite::create( footer, footer, this, menu_selector(Menu::menu1Callback)) ĬCMenu* menu = CCMenu::create( menuHeader, menuGame1, menuGame2, menuFooter, NULL )







Alignitemsverticallywithpadding example ccmenu