开发者

UIButton of previous scene overlaps CCSprite

I have a UIButton that moves around randomly on the screen. On clicking on the button, a new scene is loaded that, for now, contains a CCSprite. Here is the code:

//in init
CCSprite *a = [CCSprite spriteWithFile:@"a.png"];
[a setPosition:ccp(0,0)];
[self addCh开发者_StackOverflow中文版ild:a];

Pretty straightforward, and it stumps me why after 'replaceScene' the UIButton of theHelloWorldScene.m is still visible, right on top of the Sprite. Where am I going wrong?


I'm assuming since you're adding a UIButton into a cocos2d Scene you're using the openGLView something like:

[[[CCDirector sharedDirector] openGLView] addSubView:button];

If this is the case, then before you replace your HelloWorldScene you'll need call something similar to

[button removeFromSuperview]

Where button is the name of your UIButton (in both instances).

A suggestion though would be to use a CCMenu with a CCMenuItem on your HelloWorldScene as UIKit objects don't really mesh very well with Cocos2d.


You really aren't giving enough information. The simplest answer however is that if you do not want the button to be visible anymore then remove the child (the button). You can set a tag on the button and then use [layer getChildByTag:(NSInteger)].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜