cocos2d-x项目移植到ios下加入开场动画

cocos2d-x项目移植到ios下加入开场动画,这个需要在AppController实现

AppController.h

#import <MediaPlayer/MediaPlayer.h>
@class RootViewController;

@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
    UIWindow *window;
    RootViewController    *viewController;
    MPMoviePlayerController* testMovie;
    int over;
}

@property (nonatomic,retain)  MPMoviePlayerController* testMovie;

@end

 

AppController.mm

#import <UIKit/UIKit.h>
#import "AppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"

#import "RootViewController.h"

@implementation AppController
@synthesize testMovie;

#pragma mark -
#pragma mark Application lifecycle

// cocos2d application instance
static AppDelegate s_sharedApplication;
EAGLView *__glView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    // Override point for customization after application launch.
   
    // Add the view controller's view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    //[self performSelector:@selector(logoEnd:) withObject:nil afterDelay:19.0f];
   
    NSString* deviceType = [UIDevice currentDevice].model;   //获取设备名称
Log(@"deviceType = %@", deviceType);
    if([deviceType isEqualToString: @"iPhone"] || [deviceType isEqualToString: @"iPod touch"] )//根据不同设备名设置不同大小
  {
        testMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"start1" ofType:@"mp4"]]];
        [testMovie.view setFrame:CGRectMake(0,0, 480, 320)];
    }
    if([deviceType isEqualToString: @"iPad"])
    {
        testMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"start" ofType:@"mp4"]]];
        [testMovie.view setFrame:CGRectMake(0,0, 1024, 768)];
    }
   
    testMovie.controlStyle = MPMovieControlStyleNone;
    [testMovie play];
    [window makeKeyAndVisible];
   
   
    UIButton* skipbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];     //跳过动画的按钮

    if([deviceType isEqualToString: @"iPhone"] || [deviceType isEqualToString: @"iPod touch"])
    {
        [skipbtn setFrame:CGRectMake(380, 10, 60, 20)]; //设置button的frame
        [skipbtn setBackgroundImage: [UIImage imageNamed:@"skip1.png"] forState:UIControlStateNormal];
    }
    if([deviceType isEqualToString: @"iPad"])
    {
        [skipbtn setFrame:CGRectMake(860, 20,119,40)]; //设置button的frame
        [skipbtn setBackgroundImage: [UIImage imageNamed:@"skip1.png"] forState:UIControlStateNormal];
    }
   
    [skipbtn addTarget:self action:@selector(testBtn2Click:) forControlEvents:UIControlEventTouchUpInside];
  
    [testMovie.view addSubview:skipbtn];
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    [viewController.view addSubview:testMovie.view];
   

//视频播放结束的监听
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoEnd:) name:MPMoviePlayerPlaybackDidFinishNotification object:testMovie];
   
    [window addSubview:viewController.view];
    // Set RootViewController to window
   
   
   
    [[UIApplication sharedApplication] setStatusBarHidden: YES];
    return YES;
}

-(void)testBtn2Click:(id)sender
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:testMovie];  //移除监听
[self logoEnd:nil];
}

-(void)logoEnd:(NSNotification*)sender{
    over=1;
    [testMovie stop];
    [testMovie.view removeFromSuperview];
    [viewController.view removeFromSuperview];
    [viewController release];
    viewController = NULL;
   
    __glView = [EAGLView viewWithFrame: [window bounds]
                           pixelFormat: kEAGLColorFormatRGBA8
                           depthFormat: GL_DEPTH_COMPONENT16
                    preserveBackbuffer: NO
                            sharegroup: nil
                         multiSampling: NO
                       numberOfSamples: 0 ];
   
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = __glView;
    [__glView setUserInteractionEnabled:YES];
    [window addSubview:viewController.view];
    cocos2d::CCApplication::sharedApplication()->run();
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
    cocos2d::CCDirector::sharedDirector()->pause();
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
    cocos2d::CCDirector::sharedDirector()->resume();
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground();
    if(over!=1)
    {
        [testMovie pause];
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
    cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();
    if(over!=1)
    {
        [testMovie play];
    }
}

- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
     cocos2d::CCDirector::sharedDirector()->purgeCachedData();
}


- (void)dealloc {
    [super dealloc];
}


@end

 

这里还需注意的一点就是该项目需要加视频播放的第三方库MediaPlayer.framework,这个在Build Phases中的Link Binary With Libraries添加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值