"IOS" COCOS2DX package for view convenience to do 3D animation effect

Source: Internet
Author: User

Copyright statement: This article for the original blogger, if you need to reprint, please specify the source. It 's written in front .

This document simply encapsulates COCOS2DX as a uiview to facilitate the direct addition of use

Coco2d-x version used for 3.13.1 add process

First add ~/cocos2d/build/cocos2d_lib.xcodeproj to the project

Then modify the configuration against the new project:

Then add two Header Search Paths, same control Sample project

Set header Search Paths in targets


Set header Search Paths in project, relative path


Set up a preprocessing macro definition, Debug and release

Modify Custom Compiler Flags

At this point, no unexpected compilation can succeed. Set View

Then, in the Cocosviewcontroller (my own Test interface), set up the pop-up HelloWorld interface, the HelloWorld interface of the two classes Appdelegate and Helloworldscene to add to the project.

Note that this file is C + + mixed, so cocosviewcontroller.m file to change the suffix to cocosviewcontroller.mm

#import "CocosViewController.h" #import "CocosAppDelegate.h" #import "Platform/ios/cceaglview-ios.h" #import "

Platform/ios/ccdirectorcaller-ios.h "//cocos2d Application instance static Cocosappdelegate s_sharedapplication;
@interface Cocosviewcontroller () @property (weak, nonatomic) UIView *blackview;

@property (Weak, nonatomic) Cceaglview *eaglview;
    @end @implementation Cocosviewcontroller-(void) viewdidload {[Super viewdidload];

    Do no additional setup after loading the view.
    Self.view.backgroundColor = [Uicolor Whitecolor];

[Self DrawButton];  #pragma mark-Draw button-(void) DrawButton {UIButton *cocoabutton = [[UIButton alloc] Initwithframe:cgrectmake (0, 70,
    80, 50)];
    [Cocoabutton settitle:@ "animation switch" forstate:uicontrolstatenormal];
    [Cocoabutton Settitlecolor:[uicolor Bluecolor] forstate:uicontrolstatenormal];
    [Cocoabutton addtarget:self Action: @selector (Presentcocosview) forcontrolevents:uicontroleventtouchupinside]; [Self.view AddSUbview:cocoabutton];
        }-(void) Presentview {if (self.blackview) {[Self.blackview Removefromsuperview];
    Self.blackview = nil; else {UIView *view = [[UIView alloc] Initwithframe:cgrectmake (m, UIScreen mainscreen].bounds.size.width
        /2.0, [UIScreen mainscreen].bounds.size.height/2.0)];
        [View Setbackgroundcolor:[uicolor Blackcolor]];

        [Self.view Addsubview:view];
    Self.blackview = view;
    }}-(void) Presentcocosview {if (Self.eaglview) {[Self destroycocosview];
    else {[Self addcocosview];

    }-(void) Addcocosview {cocos2d::application *app = cocos2d::application::getinstance ();
    Initialize the Glview attributes App->initglcontextattrs ();

    Cocos2d::glviewimpl::convertattrs (); Initialize the Cceaglview cceaglview *eaglview = [Cceaglview viewwithframe:cgrectmake (0, UIScreen mainscreen ].bounds.size.width, [UIScreen mainscreen].bounds.size.height * 0.8) PixelFormat: (__bridge nsstring *) Cocos2d::glviewimpl::_pixelformat Depthformat:cocos2d::glviewimpl::_depthformat Preserv Ebackbuffer:no Sharegroup:nil Multisamp

    Ling:no numberofsamples:0];

    Enable or disable multiple touches [Eaglview setmultipletouchenabled:no];
    Set Eaglview as view of Rootviewcontroller//Self.view = Eaglview;
    [Self.view Addsubview:eaglview];

    Self.eaglview = Eaglview;

    Cocos2d::glview *glview = Cocos2d::glviewimpl::createwitheaglview ((__bridge void *) Eaglview);


    Set the Glview as Openglview of the Director cocos2d::D irector::getinstance ()->setopenglview (Glview);
Run the Cocos2d-x game Scene App->run (); }-(void) Destroycocosview {//cocos2d::D irector::GetInstance ()->gettexturecache () cocos2d::P oolmanager::d estroyinstance ();
    Cocos2d::D irector::getinstance ()->purgecacheddata ();

    Cocos2d::D irector::getinstance ()->purgedirector ();
[Ccdirectorcaller destroy];
    }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. } @end

At this point you can repeatedly turn off the Cocos animation interface. release Cocos single Case check a single case

Here first of all cocos2dx in the single case to check, mainly want to use director destroy other single cases, the results of the inspection proved Wang Zhe said: With director to manage the project in the single case, the specific release in the above Destroycocosview method. That is:

-(void) Destroycocosview
{
    //    cocos2d::D irector::getinstance ()->gettexturecache ()
    cocos2d:: Poolmanager::d estroyinstance ();
    Cocos2d::D irector::getinstance ()->purgecacheddata ();
    Cocos2d::D irector::getinstance ()->purgedirector ();

    [Ccdirectorcaller destroy];
}

Here is the check result table:

Is
Single Casereleased by Cocostudio whether to be instantiated at startup
Armaturenodereader::d estroyinstance () Is Whether
Buttonreader::d estroyinstance () Is Whether
Actionmanagerex::d estroyinstance () Is Ccactionnode and Ccsguireader
Bonenodereader::d estroyinstance () Whether Whether
Actiontimelinecache::d estroyinstance () Csloader will call this destroy when destroyed Csloader
Animation3dcache::d estroyinstance () Whether Whether
Animationcache::d estroyinstance () Is Ccnodelloader and Ccsprite
Scriptenginemanager::d estroyinstance () Whether There are a bunch of classes that use this instance but are not destroyed but can be destroyed with application
Poolmanager::d estroyinstance () Whether Ditto
Armaturedatamanager::d estroyinstance () Is Whether
Asynctaskpool::d estroyinstance () Is The other 3 classes are useful to
Configuration::d estroyinstance () Is More than 20 classes used to
FileUtils::d estroyinstance () Is
Glprogramcache::d estroyinstance () Is
Glprogramstatecache::d estroyinstance () Is
Nodeloaderlibrary::d estroyinstance () Whether Whether
__notificationcenter::d estroyinstance () Whether Whether
Guireader::d estroyinstance () Is More than 10 class calls
Sprite3dcache::getinstance () Whether Call yourself
Sprite3dmaterialcache::d estroyinstance () Whether
Spriteframecache::d estroyinstance () Is
Scenereader::d estroyinstance () Is
Dictionaryhelper::d estroyinstance () Is
Userdefault::d estroyinstance () Is
Checkboxreader::d estroyinstance () Is
Nodereader::d estroyinstance () Is
Singlenodereader::d estroyinstance () Is
Spritereader::d estroyinstance () Is
Particlereader::d estroyinstance () Is
Gamemapreader::d estroyinstance () Is
Projectnodereader::d estroyinstance () Is
Comaudioreader::d estroyinstance () Is
Widgetreader::d estroyinstance () Is
Checkboxreader::d estroyinstance () Is
Imageviewreader::d estroyinstance () Is
Textbmfontreader::d estroyinstance () Is
TextReader::d estroyinstance () Is
Textfieldreader::d estroyinstance () Is
Textatlasreader::d estroyinstance () Is
Loadingbarreader::d estroyinstance () Is
Sliderreader::d estroyinstance () Is
Layoutreader::d estroyinstance () Is
Scrollviewreader::d estroyinstance () Is
Pageviewreader::d estroyinstance () Is
Listviewreader::d estroyinstance () Is
Node3dreader::d estroyinstance () Is
Sprite3dreader::d estroyinstance () Is
Usercamerareader::d estroyinstance () Is
Particle3dreader::d estroyinstance () Is
Csloader::d estroyinstance () Is
Flatbuffersserialize::d estroyinstance () Whether A bunch of calls to this
Gamenode3dreader::d estroyinstance () Whether Whether
HttpClient::d estroyinstance () Whether Whether
Light3dreader::d estroyinstance () Whether Whether
Jsonlocalizationmanager::d estroyinstance () Whether Whether
Binlocalizationmanager::d estroyinstance () Whether Whether
Objectfactory::d estroyinstance () Whether Is
Skeletonnodereader::d estroyinstance () Whether Whether
Socketio::d estroyinstance () Whether Whether
Tabcontrolreader::d estroyinstance () Whether Whether
Tabheaderreader::d estroyinstance () Whether Whether
Tabitemreader::d estroyinstance () Whether Whether
TRIGGERMNG::d estroyinstance () Is
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.