CCControlSlider Help


#1

Hi,

I am trying to use the CCControlSlider inside my game to control the music/SFX volumes. The only twist is that I am using cocosbuilder to setup the layouts for my scenes and the track, thumb, and progress are all CCSprites that I load in. Has anyone achieved something similar to what I am trying to do? Pretty much I’d like to animated the scene in using cocosbuilder but still use the functionality from the CCControlSlider Class. Here is how I load in the code:

bool OptionsLayer::onAssignCCBMemberVariable(CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode) 
{

    CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMusicTrack", CCSprite*, mMusicTrack);
    CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMusicProgress", CCSprite*, mMusicProgress);
    CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMusicThumb", CCSprite*, mMusicThumb);

    return false;
}

void OptionsLayer::onNodeLoaded(cocos2d::CCNode * pNode,  cocos2d::extension::CCNodeLoader * pNodeLoader) 
{

    CCPoint musicSliderPos = mMusicTrack->getPosition();
        // Hack I remove these sprites since they are added to the CCControlSlider.
    removeChild(mMusicTrack, false);
    removeChild(mMusicProgress, false);
    removeChild(mMusicThumb, false);

    CCControlSlider* musicSlider = CCControlSlider::create(mMusicTrack, mMusicProgress, mMusicThumb);

    musicSlider->setAnchorPoint(ccp(0.5f, 1.0f));
    musicSlider->setPosition(musicSliderPos);

    musicSlider->setMinimumValue(0.0f); // Sets the min value of range
    musicSlider->setMaximumValue(1.0f); // Sets the max value of range
    musicSlider->setValue(0.0f);
    musicSlider->setTag(1);

    //same with restricted
    musicSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(OptionsLayer::ValueChanged), CCControlEventValueChanged);

    addChild(musicSlider);
}

The code above works 50%, the progress bar is just off by half of its width.

Thanks!