Displaying part of the sprite

46 views Asked by At

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? =)

1

There are 1 answers

0
ssantos On BEST ANSWER

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.