Setting Anchor point or changing content size of a sprite running an animation action

Setting Anchor point or changing content size of a sprite running an animation action
0.0 0

#1

I have an animated progress bar in my game. The animation play endlessly and I want to be able to change the content size of the sprite so it will show the progress bar moving while the animation still playing.

I trying to use sprite.setcontentSize(…) but it seems to have no effect on sprite playing an animation via action.

Also, Anchor point seems to always be 0.5 no matter if I try to change it.

Is there any way around it?


#2

Have you got a code snippet you can share? I’m not sure why the anchor point is not working. However, changing the size of a Sprite however must be done with setScale. The content size of a sprite is the size of the original image.

For example (with the C++ API):

Size desiredSize{100, 100};
sprite->setScaleX( desiredSize.width / sprite->getContentSize().width );
sprite->setScaleY( desiredSize.height / sprite->getContentSize().height );

#3

Using your scale method will provide a different result then what I want. I don’t want to scale it. I want that the sprite will show only part of its original size.

I manage to solve it using a clipping node and a stencil buffer. :slight_smile: