这是我的代码:
#import "VirusViewController.h"
#import "MainGame.h"
#import "cocos2d.h"
@implementation VirusViewController
@synthesize window;
- (void)loadView {
// Initialization code
CC_DIRECTOR_INIT();
CCDirector *director = [CCDirector sharedDirector];
//landscape
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDisplayFPS:YES];
//turn on multi-touch
EAGLView *cocosView = [director openGLView];
[cocosView setMultipleTouchEnabled:YES];
self.view = cocosView;
//default texture formats...
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[MainGame scene]];
}
-(void)viewDidLoad
{
UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 40, 64, 64)];
[nextButton setImage:[UIImage imageNamed:@"homeButton.png"] forState:UIControlStateNormal];
[nextButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextButton];
[nextButton release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[[CCDirector sharedDirector] purgeCachedData];
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[[CCDirector sharedDirector] release];
[window release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
-(void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}当我输入nextButton ()时,CC_Director_INIT没有接收到触摸事件;
另外,- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event不在MainGame.h的子视图中工作。
换句话说..。我不能接受任何触摸事件
发布于 2011-03-07 13:32:42
尝试给你的图层以下方法
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
} 发布于 2013-04-17 14:57:03
不建议使用sharedDispatcher --您应该使用以下方法:
[[CCDirector sharedDirector] touchDispatcher]https://stackoverflow.com/questions/5219563
复制相似问题