cocos2d-x 3.1.1 学习笔记[21]cocos2d-x 创建过程

文章出自于  http://blog.csdn.net/zhouyunxuan

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController {

}
- (BOOL) prefersStatusBarHidden;

@end

RootViewController.cpp

#import "RootViewController.h"
#import "cocos2d.h"
#import "CCEAGLView.h"

@implementation RootViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

*/
// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    return UIInterfaceOrientationMaskAllButUpsideDown;
#endif
}

//是否自己主动旋转
- (BOOL) shouldAutorotate {
    return YES;
}

//这个函数时用来确定我们的应用所支持的旋转方向。假设想要支持每一个方向则直接返回YES即可,还能够单独推断某一方向:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

    //设置旋转到某个地方
    /*
     UIInterfaceOrientationPortrait: 正常
     UIInterfaceOrientationPortraitUpsideDown: 转180度
     UIInterfaceOrientationLandscapeLeft: 向左转90度
     UIInterfaceOrientationLandscapeRight: 向右转90度
     */
    //处理转移到某个角度的时候要做的事情
    if (fromInterfaceOrientation == UIInterfaceOrientationPortrait) {
        //
    }
    else if (fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //
    }
    else if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //
    }
    else if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
        //
    }

    cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();

    if (glview)
    {
        CCEAGLView *eaglview = (CCEAGLView*) glview->getEAGLView();

        if (eaglview)
        {
            CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]);
            cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height);
        }
    }
}

//fix not hide status on ios7
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

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

@end

AppController.h

#import <UIKit/UIKit.h>

@class RootViewController;

@interface AppController : NSObject <UIApplicationDelegate> {
    UIWindow *window;
}

@property(nonatomic, readonly) RootViewController* viewController;

@end

AppController.mm

#import "AppController.h"
#import "CCEAGLView.h"
#import "cocos2d.h"
#import "AppDelegate.h"
#import "RootViewController.h"

@implementation AppController

#pragma mark -
#pragma mark Application lifecycle

// cocos2d application instance
static AppDelegate s_sharedApplication;

- (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]];

    // Init the CCEAGLView
    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
                                     pixelFormat: kEAGLColorFormatRGBA8
                                     depthFormat: GL_DEPTH24_STENCIL8_OES
                              preserveBackbuffer: NO
                                      sharegroup: nil
                                   multiSampling: NO
                                 numberOfSamples: 0];

    // Use RootViewController manage CCEAGLView
    _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    _viewController.wantsFullScreenLayout = YES;
    _viewController.view = eaglView;

    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        // warning: addSubView doesn't work on iOS6
        [window addSubview: _viewController.view];
    }
    else
    {
        // use this method on ios6
        [window setRootViewController:_viewController];
    }

    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden:true];

    // IMPORTANT: Setting the GLView should be done after creating the RootViewController
    cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);
    cocos2d::Director::getInstance()->setOpenGLView(glview);

    cocos2d::Application::getInstance()->run();

    return YES;
}

- (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.
     */
     //We don't need to call this method any more. It will interupt user defined game pause&resume logic
    /* cocos2d::Director::getInstance()->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.
     */
     //We don't need to call this method any more. It will interupt user defined game pause&resume logic
    /* cocos2d::Director::getInstance()->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::Application::getInstance()->applicationDidEnterBackground();
}

- (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::Application::getInstance()->applicationWillEnterForeground();
}

- (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.
     */
}

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

@end
didFinishLaunchingWithOptions
2014-07-28 10:07:41.247 SKT iOS[1024:60b] cocos2d: surface size: 1024x768
cocos2d: GLView End
cocos2d:
{
	cocos2d.x.version: cocos2d-x 3.1.1 - modify by zyx
	cocos2d.x.compiled_with_gl_state_cache: true
	cocos2d.x.build_type: DEBUG
	gl.supports_vertex_array_object: true
	cocos2d.x.compiled_with_profiler: false
	gl.renderer: Apple Software Renderer
	gl.vendor: Apple Computer, Inc.
	gl.max_texture_size: 4096
	gl.max_samples_allowed: 4
	gl.version: OpenGL ES 2.0 APPLE-9.4.3
	gl.supports_S3TC: false
	gl.supports_ATITC: false
	gl.supports_ETC1: false
	gl.max_texture_units: 8
	gl.supports_PVRTC: true
	gl.supports_NPOT: true
	gl.supports_discard_framebuffer: true
	gl.supports_BGRA8888: false
}

libpng warning: iCCP: known incorrect sRGB profile
cocos2d: GLProgramState::init
cocos2d: Director End
AppDelegate::applicationDidFinishLaunching()
cocos2d: Application End
applicationDidBecomeActive
Application 单例的实现方法
//静态函数调用的时候会运行一次构造函数,这个时候就初始化这个对象了。
Application* Application::getInstance()
{
    CC_ASSERT(sm_pSharedApplication);
    return sm_pSharedApplication;
}
//初始化
Application* Application::sm_pSharedApplication = 0;
//Application的构造函数
Application::Application()
{
    //在构造函数里面初始化sm_pSharedApplication
    CC_ASSERT(! sm_pSharedApplication);
    sm_pSharedApplication = this;
}
//Application的析构函数
Application::~Application()
{
    CC_ASSERT(this == sm_pSharedApplication);
    sm_pSharedApplication = 0;
}
Director 单例实现方法
static DisplayLinkDirector *s_SharedDirector = nullptr;
static Director* getInstance();
Director* Director::getInstance()
{
    if (!s_SharedDirector)
    {
        s_SharedDirector = new DisplayLinkDirector();
        s_SharedDirector->init();
    }

    return s_SharedDirector;
}
void Director::setOpenGLView(GLView *openGLView)
{
    CCASSERT(openGLView, "opengl view should not be null");

    if (_openGLView != openGLView)
    {
        // Configuration. Gather GPU info
        Configuration *conf = Configuration::getInstance();
        conf->gatherGPUInfo();
        CCLOG("%s\n",conf->getInfo().c_str());

        if(_openGLView)
            _openGLView->release();
        _openGLView = openGLView;
        _openGLView->retain();

        // set size
        _winSizeInPoints = _openGLView->getDesignResolutionSize();

        createStatsLabel();

        if (_openGLView)
        {
            setGLDefaultValues();
        }

        //初始化renderer
        _renderer->initGLView();

        CHECK_GL_ERROR_DEBUG();

        if (_eventDispatcher)
        {
            _eventDispatcher->setEnabled(true);
        }
    }
}
时间: 2024-08-07 21:17:37

cocos2d-x 3.1.1 学习笔记[21]cocos2d-x 创建过程的相关文章

cocos2d-x 3.1.1 学习笔记[3]Action 动作

这些动画貌似都非常多的样子,就所有都创建一次. 代码例如以下: /* 动画*/ auto sp = Sprite::create("card_bg_big_26.jpg"); Size size = Director::getInstance()->getWinSize(); sp->setScale(0.2); sp->setPosition(Vec2(size.width / 2 + 200, size.height / 2 + 200)); sp->set

[XMPP]iOS聊天软件学习笔记[三]

今天做了好友界面,其实xmpp内部已经写好很多扩展模块,所以使用起来还是很方便的 开发时间:五天(工作时间) 开发工具:xcode6 开发平台:iOS8 XMPP框架:XMPPFramework git clone https://github.com/robbiehanson/XMPPFramework.git 界面设计:使用StoryBoard github地址:https://github.com/hjandyz/XMPP 1.每一个模块创建以后都需要激活,比如自动连接模块 //自动连接模

[XMPP]iOS聊天软件学习笔记[四]

昨天完成了聊天界面,基本功能算告一段落 开发时间:五天(工作时间) 开发工具:xcode6 开发平台:iOS8 XMPP框架:XMPPFramework git clone https://github.com/robbiehanson/XMPPFramework.git 界面设计:使用StoryBoard github地址:https://github.com/hjandyz/XMPP 1.关于socket在后台的运行,iOS8可以直接使用(但是我自由在模拟器成功,真机不知为何不可以),ios

cocos2d-x 3.1.1 学习笔记[17] 关于函数的那些勾当

对于cocos2d-x经常要用到的方法,不得不好好研究一下,这次的研究真心有收获. 首先定义一个精灵,实现一连串连续的动作. 为了动作能够回调我们的函数,我们必须先声明并实现他们. void callBack(); void callBack_1(Node* node); void callBack_2(Node* node,const char* str); void Nice::callBack() { log("Nice::callBack()"); } void Nice::c

gcc 学习笔记(一) - 编译C程序 及 编译过程

一. C程序编译过程 编译过程简介 : C语言的源文件 编译成 可执行文件需要四个步骤, 预处理 (Preprocessing) 扩展宏, 编译 (compilation) 得到汇编语言, 汇编 (assembly) 得到机器码, 连接 (linking) 得到可执行文件; -- 查看每个步骤的编译细节 : "-E" 对应 预处理, "-S" 对应 编译, "-c" 对应 汇编, "-O" 对应 连接; -- 每个步骤对应的工

quick-cocos2d-x学习笔记【3】——display.newSprite创建精灵

游戏嘛,没图片没画面能叫游戏吗,所以我们还是先看用quick的方式怎么创建精灵. quick的api中对精灵的创建讲解得还是很详细,所以创建起来很简单. display.newSprite(filename, x, y, params) filename:精灵文件名 x:x位置坐标 y:y位置坐标 params:表参数(不常用) 我们创建的时候为了方便,可以添加x,y参数,这样就不用在后面再设置位置了.此外,对于精灵的文件名,我们在使用cocos2dx的时候,都知道有直接从文件读取,也有的是从缓

Django学习笔记(一)——安装,创建项目,配置

疯狂的暑假学习之 Django学习笔记(一) 教材  书<The Django Book> 视频:csvt Django视频 1.创建项目 django‐admin.py startproject mysite. 2.执行开发server python manage.py runserver 3.文件结构 mysite/ ├── manage.py └── mysite ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py mange.

python数据分析入门笔记[1]

1.Numpy: Numpy是python科学计算的基础包,它提供以下功能(不限于此): (1)快速高效的多维数组对象naarray (2)用于对数组执行元素级计算以及直接对数组执行数学运算的函数 (3)用于读写硬盘上基于数组的数据集的工具 (4)线性代数运算.傅里叶变换,以及随机数生成 (5)用于将C.C++.Fortran代码集成到python的工具 2.pandas pandas提供了使我们能够快速便捷地处理结构化数据的大量数据结构和函数.pandas兼具Numpy高性能的数组计算功能以及

【JAVAWEB学习笔记】21

今天主要学习了数据库的多条件查询.attr和prop的区别和分页的实现 一.实现多条件查询 public List<Product> findProductListByCondition(Condition condition) throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); //定义一个存储实际参数的容器 List<String> list =