views:

18

answers:

0

hi, I am using UIWebView to display the scrolling text in a scene in cocos2d. Some times the text is appearing in the next scene also. And it is not disappeared in any next scene. When I restart the game it is again fine. I released it and removed it from superview. But the problem occurs only some times . I could not get where I am wrong in my program. Can you suggest me.

-(id)init
{
    if((self = [super init]))
    {
        self.isTouchEnabled  = YES; 
//This is button with text. When I touch this it takes to next scene.  

        CCMenuItem *buttonItem = [CCMenuItemImage itemFromNormalImage:@"buttonA.png" selectedImage:@"buttonB.png" target:self selector:@selector(buttonPressed:)];
        CCMenu *buttonMenu = [CCMenu menuWithItems: buttonItem, nil] ;
        [buttonMenu alignItemsVertically];
        buttonMenu.position = ccp(windowSize.width/2 + 200, windowSize.height/2-60);
        [self addChild:buttonMenu z:1];

//I am adding the scrolling text here.
        self.myUIWebView = [[UIWebView alloc]initWithFrame:CGRectMake(10, 10, 250, 250)];
        [self.myUIWebView loadData:contentData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[ NSURL URLWithString:@"" ]];
        [self.myUIWebView setBackgroundColor:[UIColor clearColor]];
        [self.myUIWebView setOpaque:NO];
        self.myUIWebView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS( 90.0f ));
        [[[CCDirector sharedDirector] openGLView] addSubview:self.myUIWebView];
    }
    return self;
}  

-(void)buttonPressed:(id)sender
{
    [self.myUIWebView removeFromSuperview];

    CCScene *Scene = [CCScene node];
    CCLayer *Layer = [ChoicesScreen node];
    [Scene addChild: Layer];
    [[CCFastDirector sharedDirector] replaceScene: Scene];
}


-(void)dealloc
{
    [self.myUIWebView release];

    [super dealloc];
}  

Thank You.