我有一個CCLayer與我的應用程序的開始菜單,我想在後臺播放短片。 我已經成功地在glView中播放電影,但播放菜單時沒有描述。 要處理的電影我實例化的MPMoviePlayerController 然後我添加視圖到glView這樣:cocos2d:在菜單背景中播放視頻
[[[CCDirector sharedDirector] openGLView] addSubview:moviePlayer.view];
我已經看到了這個問題頗爲相似
How to have a menu when a movie is playing-iphone cocos2d
但我想知道是否有更好的解決方案,可能會讓我仍然利用cocos2d框架實體(而不是我自己的視圖)。
我試圖發送moviePlayer.view來支持這一方式
[theView sendSubviewToBack:moviePlayer.view];
但菜單STIL由電影隱藏...
(多小時後..)
好吧,你可以在第一個評論中看到我已經意識到(可能)唯一的方法是利用自定義視圖。我做到了,它通過在moviePlayer.view之後向glView中添加任何視圖來在模擬器中運行。但是,當我在3.1.3 FW的目標IPod touch上運行它時,電影視圖總是處於頂部。 因此,我已經意識到MPMoviePlayerController實際上創建了自己的窗口和它自己的視圖。有些帖子(如Overlay on top of Streaming MPMoviePlayerController)建議攔截新窗口加載的事件,然後添加子視圖。
這就是我試圖做的事情,但事實上從來沒有在模擬器上或目標Ipod上捕捉到。 因此,我已加入計劃的選擇 - 這是實現這種方式(空)更新:
-(void) update{
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
UIView *theView = [[CCDirector sharedDirector] openGLView];
[logo setCenter:ccp(240,80)];
[moviePlayer.view addSubview:logo];
[self unscheduleAllSelectors];
}
}
但電影仍然在上面
請你們任何幫助將非常感謝!
(幾天後...) 我也等了2秒,而電影實際上正在運行,以添加我的標識視圖作爲電影播放器的子視圖。它可以在模擬器上正常工作,但是在Ipod(3.1.3)上它會產生不同的結果。電影第一次播放時,徽標沒有被描繪(電影在最上面)。然而,因爲一旦電影完成播放方法被冷卻,從第二次開始,標誌被描述爲背景上的電影(我是否會)。這對你有意義嗎?
我真的需要了解如何解決這個問題,這是挺可笑的我在發展中2個月的比賽已經succeded,現在我2周卡住開始菜單:)
反正如果我有決定貼,我想解決,這樣就可以更好地找出問題所在層的整個代碼(或至少這是我的希望:))
+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
StartMenu *layer = [StartMenu node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(void) update{
timer ++;
if (timer==120){
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stupidLogo.png"]];
UIView *theView = [[CCDirector sharedDirector] openGLView];
[logo setCenter:ccp(240,80)];
//logo.transform = CGAffineTransformMakeRotation(3.14/2);
[moviePlayer.view addSubview:logo];
[self unscheduleAllSelectors];
}
}
-(id) init{
self = [super init];
[self schedule: @selector(update)];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test_005_conv_06.mp4" ofType:@""]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:@selector(view)]) {
if([MPMoviePlayerController instancesRespondToSelector:@selector(view)]){
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = FALSE;
// This does blows up in cocos2d, so we'll resize manually
// [moviePlayer setFullscreen:YES animated:YES];
[moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];
CGSize winSize = [[CCDirector sharedDirector] winSize];
moviePlayer.view.frame = CGRectMake(0, 0, winSize.height, winSize.width); // width and height are swapped after rotation
[[[CCDirector sharedDirector] openGLView] addSubview:moviePlayer.view];
[moviePlayer play];
}
} else {
// Use the old 2.0 style API
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
}
return self;
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[moviePlayer play];
}
我發現這個:http://www.cocos2d-iphone.org/forum/topic/61它的一個評論說:「它不工作,因爲imageView被添加到openGLView。似乎cocos2d可以不要使用UI對象,唯一的方法就是使用標準的UI方法,但是當涉及動畫時,它不像cocos2d那樣方便「。可能嗎?那可能不好... – Sindico 2010-12-16 20:16:33