Using CCScrollLayer

Hi,
I was working on a “world selector menu” and I found that the class CCScrollLayer is the thing I’m looking for.
I got the class from github wich I think is the newest version ( https://github.com/cocos2d/cocos2d-x-extensions/tree/master/extensions/CCScrollLayer ). The problem is, that the only instructions and examples I can find are in the original thread ( http://www.cocos2d-x.org/boards/6/topics/1090 ) and those simply don’t work. I have been googling a long time, but can’t see to find anything. I’m pretty newbish on cocos2d and c++ in general and I can’t figure this one out by myself.

Is there any way to find some examples or tutorials about this class? Any help is appreciated.

if you are still looking for solution just change the .cpp to this

  1. CGFloat becomes CCFloat
  2. kCCMenuTouchPriority becomes kCCMenuHandlerPriority
  3. CCTouchDispatcher::sharedDispatcher() becomes CCDirector::sharedDirector()>getTouchDispatcher
    # NSMutableSet becomes CCSet*
    <pre>
    #include “CCScrollLayer.h”
    #include <assert.h>
    namespace cocos2d
    {
    enum
    {
    kCCScrollLayerStateIdle,
    kCCScrollLayerStateSliding,
    };
    CCScrollLayer::CCScrollLayer
    : m_pDelegate, m_pLayers, m_bStealingTouchInProgress, m_pScrollTouch, m_iState
    {
    }
    CCScrollLayer::~CCScrollLayer
    {
    CC_SAFE_RELEASE;
    m_pDelegate = NULL;
    }
    unsigned int CCScrollLayer::getTotalScreens const
    {
    return m_pLayers
    >count();
    }

CCScrollLayer* CCScrollLayer::nodeWithLayers(CCArray* layers, int widthOffset)
{
CCScrollLayer* pRet = new CCScrollLayer();
if (pRet && pRet~~>initWithLayers)
{
pRet~~>autorelease();
return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
}

bool CCScrollLayer::initWithLayers(CCArray* layers, int widthOffset)
{
if (!CCLayer::init())
return false;
CC_ASSERT(layers && layers~~>count);
setTouchEnabled;
m_bStealTouches = true;
// Set default minimum touch length to scroll.
m_fMinimumTouchLengthToSlide = 30.0f;
m_fMinimumTouchLengthToChangePage = 100.0f;
m_fMarginOffset = CCDirector::sharedDirector~~>getWinSize.width;
// Show indicator by default.
m_bShowPagesIndicator = true;
m_tPagesIndicatorPosition = ccp);
// Set up the starting variables
m_uCurrentScreen = 0;
// Save offset.
m_fPagesWidthOffset = widthOffset;
// Save array of layers.
m_pLayers = CCArray::arrayWithArray;
layers~~>release;
m_pLayers~~>retain();

updatePages();

return true;
}

void CCScrollLayer::updatePages()
{
// Loop through the array and add the screens if needed.
int i = 0;
CCObject* object = NULL;
CCARRAY_FOREACH(m_pLayers, object)
{
CCLayer* layer = (CCLayer*)object;
layer~~>setAnchorPoint);
layer~~>setContentSize(CCDirector::sharedDirector()>getWinSize);
layer
>setPosition(ccp((i * (m_tContentSize.width - m_fPagesWidthOffset)), 0));
if (!layer->getParent())
addChild(layer);
i**;
}
}
// CCLayer Methods ReImpl
void CCScrollLayer::visit
{
CCLayer::visit; //< Will draw after glPopScene.
if
{
int totalScreens = getTotalScreens;
// Prepare Points Array
CCFloat n = totalScreens; //< Total points count in CCFloat.
CCFloat pY = m_tPagesIndicatorPosition.y; //< Points y-coord in parent coord sys.
CCFloat d = 16.0f; //< Distance between points.
CCPoint* points = new CCPoint[totalScreens];
for
{
CCFloat pX = m_tPagesIndicatorPosition.x* d * i - 0.5f**);
points[i] = ccp;
}
// Set GL Values
glEnable;
GLboolean blendWasEnabled = glIsEnabled;
glEnable;
glBlendFunc;
glPointSize);
// Draw Gray Points
glColor4ub;
ccDrawPoints;
// Draw White Point for Selected Page
glColor4ub;
ccDrawPoint;
// Restore GL Values
glPointSize;
glDisable;
if
glDisable;
delete [] points;
}
}
// Moving To / Selecting Pages
void CCScrollLayer::moveToPageEnded
{
if
m_pDelegate~~>scrollLayerScrolledToPageNumber;
}
unsigned int CCScrollLayer::pageNumberForPosition
{
CCFloat pageFloat =~~ m_tPosition.x / ;
int pageNumber = ceilf;
if pageNumber - pageFloat >= 0.5f)
pageNumber—;
pageNumber = MAX (0, pageNumber);
pageNumber = MIN ((int)m_pLayers~~>count~~ 1, pageNumber);
return pageNumber;
}

CCPoint CCScrollLayer::positionForPageWithNumber
{
return ccp, 0.0f);
}
void CCScrollLayer::moveToPage
{
if )
{
CCLOGERROR (“CCScrollLayer::moveToPage: %d - wrong page number, out of bounds.”, pageNumber);
return;
}
CCAction** changePage =
CCSequence::actionOneTwo),
CCCallFunc::actionWithTarget)
);
runAction;
m_uCurrentScreen = pageNumber;
}
void CCScrollLayer::selectPage
{
if )
{
CCLOGERROR (“CCScrollLayer::selectPage: %d - wrong page number, out of bounds.”, pageNumber);
return;
}
setPosition);
m_uCurrentScreen = pageNumber;
}
// Dynamic Pages Control
void CCScrollLayer::addPage
{
addPage);
}
void CCScrollLayer::addPage
{
pageNumber = MIN (pageNumber, m_pLayers->count());
pageNumber = MAX (pageNumber, 0);
m_pLayers~~>insertObject;
updatePages;
moveToPage;
}
void CCScrollLayer::removePage
{
m_pLayers~~>removeObject;
removeChild;
updatePages;
m_uCurrentScreen = MIN (m_uCurrentScreen, m_pLayers->count() - 1);
moveToPage;
}
void CCScrollLayer::removePageWithNumber
{
if )
removePage));
}
// Touches
// Register with more priority than CCMenu’s but don’t swallow touches
void CCScrollLayer::registerWithTouchDispatcher
{
//CCTouchDispatcher::sharedDispatcher~~>addTargetedDelegate;
CCDirector::sharedDirector~~>getTouchDispatcher~~>addTargetedDelegate;
}
/* Hackish stuff - stole touches from other CCTouchDispatcher targeted delegates.
Used to claim touch without receiving ccTouchBegan.
/
void CCScrollLayer::claimTouch
{
CCTargetedTouchHandler* handler = CCDirector::sharedDirector~~>getTouchDispatcher~~>findHandler;
if
{
CCSet* claimedTouches = handler~~>getClaimedTouches;
if )
{
claimedTouches~~>addObject;
}
else
{
CCLOGERROR (“CCScrollLayer::claimTouch is already claimed!”);
}
}
}
void CCScrollLayer::cancelAndStoleTouch
{
// Throw Cancel message for everybody in TouchDispatcher.
CCSet* touchSet = new CCSet;
touchSet~~>addObject;
touchSet~~>autorelease;
m_bStealingTouchInProgress = true;
CCDirector::sharedDirector~~>getTouchDispatcher~~>touchesCancelled;
m_bStealingTouchInProgress = false;
//< after doing this touch is already removed from all targeted handlers
// Squirrel away the touch
claimTouch;
}
void CCScrollLayer::ccTouchCancelled
{
// Do not cancel touch, if this method is called from cancelAndStoleTouch:
if
return;
if
{
m_pScrollTouch = NULL;
selectPage;
}
}
bool CCScrollLayer::ccTouchBegan
{
if
m_pScrollTouch = pTouch;
else
return false;
CCPoint touchPoint = pTouch~~>locationInView;
touchPoint = CCDirector::sharedDirector~~>convertToGL;
m_fStartSwipe = touchPoint.x;
m_iState = kCCScrollLayerStateIdle;
return true;
}
void CCScrollLayer::ccTouchMoved
{
if
return;
CCPoint touchPoint = pTouch~~>locationInView;
touchPoint = CCDirector::sharedDirector~~>convertToGL;
// If finger is dragged for more distance then minimum~~ start sliding and cancel pressed buttons.
// Of course only if we not already in sliding mode
if
&& >= m_fMinimumTouchLengthToSlide))
{
m_iState = kCCScrollLayerStateSliding;
// Avoid jerk after state change.
m_fStartSwipe = touchPoint.x;
if
cancelAndStoleTouch;
if
m_pDelegate~~>scrollLayerScrollingStarted;
}
if
{
float desiredX = ) + touchPoint.x~~ m_fStartSwipe;
unsigned int page = pageNumberForPosition);
float offset = desiredX - positionForPageWithNumber.x;
if || - 1 && offset < 0))
offset = m_fMarginOffset * >getWinSize.width);
else
offset = 0;
setPosition);
}
}
void CCScrollLayer::ccTouchEnded
{
if
return;
m_pScrollTouch = NULL;
CCPoint touchPoint = pTouch
>locationInView;
touchPoint = CCDirector::sharedDirector
>convertToGL;
unsigned int selectedPage = m_uCurrentScreen;
float delta = touchPoint.x~~ m_fStartSwipe;
if >= m_fMinimumTouchLengthToChangePage)
{
selectedPage = pageNumberForPosition;
if
{
if~~ 1)
selectedPage*+;
else if (delta > 0.f && selectedPage > 0)
selectedPage—;
}
}
moveToPage(selectedPage);
}
}

m_tContentSize what is??, Use of undeclared identifier…

Does this issue have a solution?

change “m_tContentSize” to “m_obContentSize”

Is there a git of this somewhere that I can download? I’m also getting a slew of “does not have default constructor” messages on
@
CCScrollLayer::CCScrollLayer()
: m_pDelegate(NULL), m_pLayers(NULL), m_bStealingTouchInProgress(false), m_pScrollTouch(NULL), m_iState(kCCScrollLayerStateIdle)@

Really am curious as to how others have gotten this code to work.

I had to add
@
m_fMarginOffset(0), m_fPagesWidthOffset(0), m_fStartSwipe(true), m_fMinimumTouchLengthToChangePage(0),m_fMinimumTouchLengthToSlide(0)@
(assuming those initial conditions are right)

And now I’m getting at least 11 errors. They appear to be mostly focused on:

1: Mixing float and cocos2d::CCFloat operands
2: OpenGL issues with GL_POINT_SMOOTH and glColor4ub. Other GL functions appear to work fine.

Is there some clean code out there that works? If not, how do I fix the OpenGL issues?

I should mention I’m using 2.1.3

@PWiggin Do you got a solution last? I had the same problem.