Sprite scaling help

I am trying to make a customized progress bar. What I want to do is to have “barMask.png” have it’s X scale depending on a percentage of the number. I’ve tried to do it like this:

barBack = CCSprite::create( "barBack.png" );
this -> addChild( barBack );

barMask = CCSprite::create( "barMask.png" );
barMask -> setPosition( barBack -> getPosition( ) );
this -> addChild( barMask );

Then on the update method

// Scale the width of barMask depending on the percentage of the progress.
barMask -> setScaleX( CURRENT_AMOUNT / TOTAL_AMOUNT );

However, the sprite is scaled like this:

Frame 1: [ |||||||||| ]
Frame 2: [  ||||||||  ]
Frame 3: [   ||||||   ]

It shrinks down into the middle. How can I do so that it shrinks down to the left/right? Like this:

Frame 1: [ |||||||||| ]
Frame 2: [ |||||||||  ]
Frame 3: [ ||||||||   ]
Frame 4: [ |||||||    ]

The anchorpoint of your sprite should be set to ccp(0,0.5)

By Default the anchorpoint of a ccsprite is set to ccp(0.5 , 0.5). The following depicts the default location of the anchorpoint
STAR IS THE LOCATION OF THE ANCHORPOINT.
[=]
[**]

So the sprite scales from the middle because its anchorpoint is the centre.
If you set it to ccp that is change the origin to the following point:
**=]
[=]

then this new location becomes the origin of the sprite. Hence all scaling and rotation and translation occur about this point.

Thanks for the help. :slight_smile:

Your welcome :slight_smile: