我將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