Question

Here is my problem. The goal is to make a scale, that fills out while the char collects the food. I got 2 sprites: the scale without the filling and the filling itself. So my question is simple: how to draw a part of the filling sprite depending on the number of "apples" eaten? =)

Was it helpful?

Solution

I solved a similar problem for a loading bar some time ago, using glScissor. Basically I extended CCSprite with a float indicating the filled portion, and overrode visit method like this.-

- (void) visit {
    glEnable(GL_SCISSOR_TEST);  
    glScissor(0, 0, (loadingPercent / 100) * self.contentSize.width * CC_CONTENT_SCALE_FACTOR(), self.contentSize.height * 4);
    [super visit];
    glDisable(GL_SCISSOR_TEST);
}

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top