Hello everyone :),
The scene in question was working correctly before I tried to use a 3D transition (like the page curl) between Cocos2D scenes. This change in scene transitions caused the situation you see below (turning depth tests off for this scene made the scene look "all right" again, but the transitions between scenes would be off...)
The scenes uses various layers (the pieces of cloth are rendered using a CCSpriteBatchNode and the other layers with another one... thinking of trying to use a single atlas for all of them, but I do not know if this is the issue here... the number of objects and the draw calls overhead do not worry me too much). This happens with both an RGBA8 cocos2d FBO as well as a RGB565 one...
-(id) init
{
if( (self=[super init])) {
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = YES;
[[CCDirector sharedDirector] setDepthTest: YES];
CGSize screenSize = [CCDirector sharedDirector].winSize;
target = [[CCRenderTexture renderTextureWithWidth:screenSize.width height:screenSize.height] retain];
[target setPosition:ccp(screenSize.width/2, screenSize.height/2)];
[target.sprite runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCRipple3D actionWithPosition:MID_POINT_COCOS radius:650 waves:30 amplitude:40 grid:ccg(64, 64) duration:10], [CCStopGrid action], nil]]];
[... physics stuff...]
[self createWasherWheel];
batch = [CCSpriteBatchNode batchNodeWithFile:@"Page08/Pag8_lay2_sprite1.png" capacity:16];
[batch retain];
[self addChild:target z:2];
[self addNewSpriteWithCoords:b2Vec2(600, 400)];
CCSprite * bgL4 = [CCSprite spriteWithSpriteFrameNameOrFile:@"Page08/Pag8_lay4.png"];
[bgL4 setPosition:MID_POINT_COCOS];
CCSprite * bgL3 = [CCSprite spriteWithSpriteFrameNameOrFile:@"Page08/Pag8_lay3.png"];
[bgL3 setPosition:MID_POINT_COCOS];
bgL1 = [[CCSprite spriteWithSpriteFrameNameOrFile:@"Page08/Pag8_lay1.png"] retain];
[bgL1 setPosition:MID_POINT_COCOS];
[self addChild:bgL3 z:5];
[self addChild:bgL4 z:6];
[(OminoAppDelegate*)[[UIApplication sharedApplication] delegate] addMenuToLayer:self];
[self schedule: @selector(tick:)];
_mouseJoint = NULL;
}
return self;
}
I need to draw into the RTT in the -tick: method because I want to wapr box2D driven sprites:
-(void) tick: (ccTime) dt
{
if(dist>=0){
dist -= dt * 0.05;
dist = CLAMP_VAL(dist, 0.0f, 1.5f);
}
else {
dist += dt * 0.05;
dist = CLAMP_VAL(dist, -1.5f, 0.0f);
}
washingMachineMotor->SetMotorSpeed(dist);
[self step:dt];
[target beginWithClear:0 g:0 b:0 a:0];
//Iterate over the bodies in the physics world
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() != NULL) {
//Synchronize the AtlasSprites position and rotation with the corresponding body
CCSprite *myActor = (CCSprite*)b->GetUserData();
myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
[bgL1 visit];
[batch visit];
[target end];
}
This is the method I use to add each sprite to the scene inside the -init: method:
- (void) addNewSpriteWithCoords:(b2Vec2)p {
b2Vec2 spriteposition = p;
b2Vec2 sprite1position = p + b2Vec2(120, 15);
b2Vec2 sprite2position = p + b2Vec2(-120, -15);
CCSprite *sprite = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*0,224*0,224,224)];
[batch addChild:sprite];
sprite.position = ccp(spriteposition.x, spriteposition.y);
CCSprite *sprite1 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*1,224*0,224,224)];
[batch addChild:sprite1];
sprite1.position = ccp(sprite1position.x, sprite1position.y);
CCSprite *sprite2 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*2,224*0,224,224)];
[batch addChild:sprite2];
sprite2.position = ccp(sprite2position.x, sprite2position.y);
[... physics stuff...]
CCSprite *sprite3 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*0,224*1,224,224)];
[batch addChild:sprite3];
sprite3.position = ccp(sprite3position.x, sprite3position.y);;
CCSprite *sprite4 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*1,224*1,224,224)];
[batch addChild:sprite4];
sprite4.position = ccp(sprite4position.x, sprite4position.y);;
CCSprite *sprite5 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*2,224*1,224,224)];
[batch addChild:sprite5];
sprite5.position = ccp(sprite5position.x, sprite5position.y);;
[... physics stuff...]
CCSprite *sprite6 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*0,224*2,224,224)];
[batch addChild:sprite6];
sprite6.position = ccp(sprite6position.x, sprite6position.y);;
CCSprite *sprite7 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*1,224*2,224,224)];
[batch addChild:sprite7];
sprite7.position = ccp(sprite7position.x, sprite7position.y);;
CCSprite *sprite8 = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(224*2,224*2,224,224)];
[batch addChild:sprite8];
sprite8.position = ccp(sprite8position.x, sprite8position.y);;
[... physics stuff...]
///////////////////
[nodeSprite addChild:sprite];
[nodeSprite addChild:sprite1];
[nodeSprite addChild:sprite2];
[nodeSprite addChild:sprite3];
[nodeSprite addChild:sprite4];
[nodeSprite addChild:sprite5];
[nodeSprite addChild:sprite6];
[nodeSprite addChild:sprite7];
[nodeSprite addChild:sprite8];
}
What do you think is happening here? Simple z-ordering issue?
