Thanks for your reply
I have tried all of your things but problem is not solved yet..
I just found that if i don't call this reduceHealth method , the scene is replace just fine
otherwise it's overlapping
so plz tell me where i have been wrong
I am showing health in my game so i have just used images for that
when i call this method it just removes that health sprite so user feel that his health is getting reduced.
This is my code:
Health.h file
=============
@interface Health : CCLayer {
NSMutableArray *livesArray;
int totalHealth;
CCSpriteSheet *_spriteSheet;
}
@property (nonatomic, assign) CCSpriteSheet *spriteSheet;
@property (nonatomic,retain) NSMutableArray *livesArray;
-(void) reduceHealth;
@end
Health.m file
=============
@implementation Health
@synthesize livesArray;
@synthesize spriteSheet = _spriteSheet;
- (id) init
{
if( (self=[super init] )) {
int posX,posY;
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = NO;
totalHealth = SKIPBALLOONS_GAMEOVER;
self.spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"sprites.png"];
[self addChild:_spriteSheet z:-1];
CCSprite *healthLabel = [CCSprite spriteWithSpriteFrameName:@"label_health.png"];
healthLabel.position = ccp(GAME_HEALTH_POSX,GAME_HEALTH_POSY);
[self addChild:healthLabel];
livesArray = [[NSMutableArray alloc] initWithCapacity:totalHealth];
posX=120;
posY=420;
for (int i =0 ; i < totalHealth ; i++) {
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"2.png"];
sprite.position = ccp(posX,posY);
sprite.scale = 0.3f;
posX = posX + 20;
[livesArray addObject:sprite];
[_spriteSheet addChild:sprite];
}
}
return self;
}
-(void) reduceHealth
{
CCSprite *sprite = [livesArray objectAtIndex:totalHealth-1];
[livesArray removeLastObject];
totalHealth--;
sprite.position = ccp(10,10);
//sprite.visible = NO;
[sprite removeFromParentAndCleanup:YES];
NSLog(@"Health red..");
}
-(void) dealloc
{
[livesArray release];
[super dealloc];
}
@end