Giter Club home page Giter Club logo

cocosqtport's Introduction

CocosQtPort


This is porting code, which port cocos2d-x3.3 to QT5.3.
It is useful for coding a game editor.

How to use?
1. copy CocoQtPort directory to your Classes folder.
2. change AppDelegate to inherit form cocos2d::CCQApplication. add a member, like:
``` class AppDelegate : private cocos2d::CCQApplication { public: AppDelegate(int argc, char *argv[]) : cocos2d::CCQApplication(argc, argv) {}; virtual ~AppDelegate(); ...... protected: CCGEditor _mainWindow; // CCGEditor is the MainWindow class which you created in QT. } ```
3. modify AppDelegate::applicationDidFinishLaunching(), use CCQGLView to create glview. like:
``` bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = CCQGLView::getInstance(); glview->setBgColor(Color4B(50, 50, 50, 255));
director->setOpenGLView(glview);
_mainWindow.setGLView(glview->getGLWidget());
_mainWindow.show();

...... }

<br>
4. Modify your QT MainWindow class (here is CCGEditor):<br>
CCGEditor.h<br>

class CCGEditor : public QMainWindow { Q_OBJECT

public: CCGEditor(QWidget *parent = 0); ~CCGEditor() {}

void setGLView(QWidget *glWidget);

protected: void closeEvent(QCloseEvent *);

private: Ui::CCGEditorClass ui; AppDelegate *_appDelegate; QWidget *_glWidget; };

<br>
CCGEditor.cpp<br>

CCGEditor::CCGEditor(QWidget *parent) : QMainWindow(parent), _appDelegate(NULL), _glWidget(NULL) { ui.setupUi(this); }

void CCGEditor::closeEvent(QCloseEvent *) { cocos2d::Director::getInstance()->end(); qApp->quit(); }

void CCGEditor::setGLView(QWidget *glWidget) { _glWidget = glWidget;

if (_glWidget)
{
	ui.SceneWidget->setWidget(_glWidget);
	setCentralWidget(ui.SceneWidget);
}

}

<br>
5. modify the main function in this way:<br>

int main(int argc, char *argv[]) { AppDelegate app(argc, argv); return cocos2d::CCQApplication::getInstance()->run(); }

<br>
6. do not forget the header files_(:зゝ∠)_<br>
<br>
See my blog for detail:<br>
http://www.cnblogs.com/marisa/p/4141862.html

cocosqtport's People

Contributors

gameboy12615 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.