XCode5 adding new class templates (Cocos2dx template class for Scene or Layer)

Source: Internet
Author: User
Tags addchild

Monkey original, welcome reprint. Reprint Please specify: Reproduced from cocos2d Development network –cocos2dev.com, thank you!

Original address: http://www.cocos2dev.com/?p=505

Because the common COCOS2DX development game, every time you create a new CPP class file, Xcode default generated CPP class is basically an empty file, each time to implement the basic code of COCOS2DX. Very troublesome. (although I have modified the HelloWorld file every time, the newly created file will copy the HelloWorld content directly.) The feeling is still very troublesome. )

Today, we have modified the following class template, added 2 cocos2dx class templates, the following is the time to create a new file, there is no more than 2 class template.

Below I will say how to add Xcode class template, very simple.

1. Open Xcode's class template directory address:/applications/xcode.app/contents/developer/library/xcode/templates/file Templates

2, open the inside C and C + + files, you will see the CPP class template files Xcode. Copy a C + + Class.xctemplate folder named: 2dx Scene class.xctemplate, placed in the C and C + + directory.

3, modify the Templateinfo.plist (main changes in the creation of the document when the description of the introduction)

Open 2DX Scene class.xctemplate/templateinfo.plist, modify the value of description to: A C + + Class for cocos2d-x Scene.

4, modify the ___filebasename___.h

Open the 2DX Scene class.xctemplate/___filebasename___.h and modify it to the following:

////___filename___//___projectname___////Created by ___fullusername___ on ___date___.//___copyright___//#ifndef _____projectnameasidentifier________filebasenameasidentifier_____#define_____projectnameasidentifier________filebasenameasidentifier_____#include"cocos2d.h"using_ns_cc;class___filebasenameasidentifier___: Publiclayer{ Public: ___filebasenameasidentifier___ (); ~___filebasenameasidentifier___ (); Staticscene*Createscene (); Virtual BOOLinit ();     Create_func (___filebasenameasidentifier___); Private:    voidInitData ();}; #endif/* Defined (_____projectnameasidentifier________filebasenameasidentifier_____) */

5, modify the ___filebasename___.cpp

Open the 2DX Scene class.xctemplate/___filebasename___.cpp and modify it to the following:

////___filename___//___projectname___////Created by ___fullusername___ on ___date___.//___copyright___//#include"___filebasename___.h"___filebasenameasidentifier___::___filebasenameasidentifier___ () {} ___filebasenameasidentifier___::~___filebasenameasidentifier___ () {} Scene*___filebasenameasidentifier___::createscene () {Auto Scene=scene::create (); Auto Layer=___filebasenameasidentifier___::create (); Scene-addChild (layer); returnscene;} BOOL___filebasenameasidentifier___::init () {if( !Layer::init ()) {        return false;    } initdata (); return true;} #pragmaMark-initdatavoid___filebasenameasidentifier___::initdata () {Size visiblesize= Director::getinstance ()getvisiblesize (); //Add your codes here ...     }

OK, this completes the addition of a class template.

Now create a new 2dx scene class inside Xcode to see. There is already a default content.

////MyScene.h//Magicdemo////Created by Liuyanghui on 13-12-27.////#ifndef __magicdemo__myscene__#define__magicdemo__myscene__#include"cocos2d.h"using_ns_cc;classMyScene: Publiclayer{ Public: MyScene (); ~MyScene (); Staticscene*Createscene (); Virtual BOOLinit ();     Create_func (MyScene); Private:    voidInitData ();}; #endif/* Defined (__magicdemo__myscene__) */
////MyScene.cpp//Magicdemo////Created by Liuyanghui on 13-12-27.////#include"MyScene.h"Myscene::myscene () {} MyScene::~MyScene () {} Scene*myscene::createscene () {Auto Scene=scene::create (); Auto Layer=myscene::create (); Scene-addChild (layer); returnscene;} BOOLMyscene::init () {if( !Layer::init ()) {        return false;    } initdata (); return true;} #pragmaMark-initdatavoidMyscene::initdata () {Size visiblesize= Director::getinstance ()getvisiblesize (); //Add your codes here ...     }

The corresponding class template for which you can add a layer. method, I will not repeat.

For a pre-defined variable in the file template, the following is introduced:


OK, there are lots of interesting features that you can explore for yourself. such as project templates, plugins and so on.

Source URL: http://blog.csdn.net/cocos2der/article/details/17610001

XCode5 adding new class templates (Cocos2dx template class for Scene or Layer)

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.