我将cocos2d用于我的游戏。我在其中播放电影并为控件设置单独的叠加视图。叠加视图中检测到触摸。现在,当触摸被检测到时,游戏代码中的功能必须被调用。但是该功能未被检测到并且没有错误。我不知道出了什么问题。有人请帮助我。 的代码如下使用协议调用不同类的函数时出现问题 - iphone
协议部分是
@protocol Protocol
@required
- (void)transition1:(id)sender;
@end
这是在游戏代码被调用的功能是
- (void)transition1:(id)sender
{
[[Director sharedDirector] replaceScene: [ [Scene node] addChild: [Layer4 node] z:0] ];
}
在MovieOverlayViewController.h叠加视图的代码
#import "Protocol.h"
@interface MovieOverlayViewController : UIViewController
{
UIImageView *overlay;
NSObject <Protocol> *transfer;
}
@end
MovieOve中叠加视图中的代码rlayViewController.m
@implementation MovieOverlayViewController
- (id)init
{
if ((self = [super init]))
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
return self;
}
-(void) viewWillAppear:(BOOL)animated
{
overlay = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"overlay.png"]] autorelease];
[self.view addSubview:overlay];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
NSLog(@"pointx: %f pointy:%f", point.x, point.y);
if (CGRectContainsPoint(CGRectMake(1, 440, 106, 40), point))
{
// the function is called here
[transfer transition1: nil];
}
else if (CGRectContainsPoint(CGRectMake(107, 440, 106, 40), point))
NSLog(@"tab 2 touched");
}
- (void)dealloc
{
[overlay release];
[super dealloc];
}
@end
谢谢汝赫。 我将格式化我的下一个问题。 – Muniraj 2010-03-19 12:06:26