Question

I have made spritesheet in Zwoptex , I know TexturePacker is better than this but i have just started with cocos2d iphone, so haven't purchase that.

I have made CCTexture2D using following code. 

texture = [[CCTextureCache sharedTextureCache] addImage:@"1.png"];
    self.shaderProgram = [[CCShaderCache sharedShaderCache] programForKey:kCCShader_PositionTexture];
CC_NODE_DRAW_SETUP();

And i use this CCtexture2D object to draw texture around soft body.Using Following code.

ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);
ccGLBindTexture2D([texture name]);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, textCoords);
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_TRUE, 0, triangleFanPos);
glDrawArrays(GL_TRIANGLE_FAN, 0, NUM_SEGMENT+2);
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Color);

Now I want to animate texture of soft body. I know how to animate sprite using spritesheet. But now i am confuse how to make CCTexture2D using spritesheet and how can i animate texture using different images like we do in sprite animation?

Can anyone give me any direction in solving this issue?

Was it helpful?

Solution

First of all i want to say sorry for this question. I want to share my code here. I want to animate the texture which i am giving to the soft body.

I was confused , how can i give new image to the cctexture2d object and rotate that at the angle of previous textures angle. But I came to know that cocos2d iphone automatically handles that.

I animate my texture2d object by just giving it the image sequences with delay. Code for that is shown below.

Called Function

-(void)changeTexture1:(NSNumber*)i{
    texture = [[CCTextureCache sharedTextureCache] addImage:[NSString stringWithFormat:@"blink%@.png",i]];
}

Calling function:

-(void)makeAnimation{
    for (int i = 2; i<7; i++) {
        [self performSelector:@selector(changeTexture1:) withObject:[NSNumber numberWithInt:i] afterDelay:0.1*i];
    }
    int j = 1;
    for(int i=6;i>0;i--){
         [self performSelector:@selector(changeTexture1:) withObject:[NSNumber numberWithInt:i] afterDelay:0.1*6 + 0.1*j++];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top