Image 1 becomes image 2 with sliding effect from left to right?

Posted by Paul on Game Development See other posts from Game Development or by Paul
Published on 2012-06-13T23:13:29Z Indexed on 2012/06/16 3:24 UTC
Read the original article Hit count: 272

Filed under:
|
|

I would like to show a second image appearing while a "door" is closing on my character. I've got my character in the middle of the screen and a door coming from the left. When the door passes my character, I would like to have this second image appearing little by little.

So far, I've gotten by with fadingOut the character and then fadingIn my second image of the character at the same position when the door is completely closed, but I would like to have both of them at the same time. (the effect that image 1 becomes image 2 when the door is sliding from left to right). Would you know how to do this with Cocos2d?

Here are the images :

at first, the character is blue, and the door is coming from the left : enter image description here

Then, behind the black door, the character becomes red, but only behind this door, so it stays blue when the door is not on him, and will become completely red when the door passes the character :

enter image description here


EDIT : with this code, the black door hides the red and blue rectangles : (And if i add each of my layers at a different depth, and only use GL_LESS, same thing)

blue.position =  ccp( size.width*0.5 , size.height/2 );
        red.position =  ccp( size.width*0.46 , size.height/2 );
        black.position =  ccp( size.width*0.1 , size.height/2 );

        glEnable(GL_DEPTH_TEST);

        [batch addChild:red z:0];
        [batch addChild:black z:2];

        glDepthFunc(GL_GREATER);

        [batch addChild:blue z:1];

        glDepthFunc(GL_LESS);

        id action1 = [CCMoveTo actionWithDuration:3 position:ccp(size.width,size.height/2)];
        [black runAction: [CCSequence actions:action1, nil]];

© Game Development or respective owner

Related posts about cocos2d-iphone

Related posts about cocos2d