您好我正在尝试插入场景,cocos 2d项目,背景中的电影以及它上面的精灵对象。 我设法插入电影和精灵和interagisono,但我无法按照我的意愿将视频移到spritre下面。
我在场景中编写的代码如下:
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
lLevel0 *layer = [lLevel0 node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {
[self startMovie];
//Creo un oggetto sulla scena
sBall *ball = [sBall Ball];
CGSize size = [[CCDirector sharedDirector] winSize];
ball.position = ccp( ball.contentSize.width/2 , size.height/2 );//Carico la
posizione della palla sulla sinistra (start poosition)
[self addChild:ball z:999];
[ball moveForever];
[self beginDetectingTouch];
}
return self;
}
- (void) startMovie
{
NSString *path = [[NSBundle mainBundle]pathForResource:@"sampleVideo"
ofType:@"mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
//[[mp moviePlayer] setMovieControlMode:MPMovieControlModeHidden];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
if ([mp respondsToSelector:@selector(view)]) {
if([MPMoviePlayerControllerinstancesRespondToSelector:@selector(view)]){
// Use the new 3.2 style API
mp.moviePlayer.controlStyle = MPMovieControlStyleNone;
mp.moviePlayer.shouldAutoplay = FALSE;
// This does blows up in cocos2d, so we'll resize manually
// [moviePlayer setFullscreen:YES animated:YES];
[mp.moviePlayer.viewsetTransform:CGAffineTransformMakeRotation((float)M_PI_2)];
CGSize winSize = [[CCDirector sharedDirector]winSize];
mp.moviePlayer.view.frame = CGRectMake(0, 0, winSize.height,
winSize.width); // width and height are swapped after rotation
[[[CCDirector sharedDirector] openGLView]addSubview:mp.moviePlayer.view];
[[[CCDirector sharedDirector] openGLView]sendSubviewToBack:mp.moviePlayer.view];
[mp.moviePlayer play];
}
} else {
// Use the old 2.0 style API
mp.moviePlayer.movieControlMode =MPMovieControlModeHidden;
[mp.moviePlayer play];
}
}
- (void)moviePlayBackDidFinishs:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[moviePlayer play];
}