【问题标题】:Cocos2d-x in QtCreator on UbuntuUbuntu 上 QtCreator 中的 Cocos2d-x
【发布时间】:2013-12-24 20:11:19
【问题描述】:

我尝试在 QtCreator 中运行 cocos2d-x v 2.2 helloword 项目。我正在使用这个基于这个存储库的项目文件https://github.com/FlyingFishBird/cocos2d-x_2_0_4_templete_for_qtcreator/graphs/contributors

   TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

CONFIG(debug, debug|release) {
DESTDIR = bin/debug/
}

CONFIG(release, debug|release) {
DESTDIR = bin/release/
}


RESOURCES = Resources.qrc

SOURCES += Classes/AppDelegate.cpp  \
    Classes/HelloWorldScene.cpp \
    proj.linux/main.cpp

HEADERS +=Classes/AppDelegate.h \
    Classes/HelloWorldScene.h


COCOS2DX_ROOT = $$system(echo $COCOS2DX_ROOT)

# set include path and depend path
COCOS_INCLUDE_DEPEND_PATH += $$COCOS2DX_ROOT/cocos2dx \
        $$COCOS2DX_ROOT/cocos2dx/include \
        $$COCOS2DX_ROOT/cocos2dx/cocoa \
        $$COCOS2DX_ROOT/cocos2dx/kazmath/include \
        $$COCOS2DX_ROOT/cocos2dx/platform \
        $$COCOS2DX_ROOT/CocosDenshion/include \
        $$COCOS2DX_ROOT/extensions \
        $$COCOS2DX_ROOT/external


    DEFINES += LINUX

        COCOS_INCLUDE_DEPEND_PATH += $$COCOS2DX_ROOT/cocos2dx/platform/linux

    LBITS = $$system(getconf LONG_BIT)

        contains(LBITS,64) {
                COCOS_INCLUDE_DEPEND_PATH += $$COCOS2DX_ROOT/platform/third_party/linux/include64
                STATICLIBS_DIR += $$COCOS2DX_ROOT/cocos2dx/platform/third_party/linux/libraries/lib64
        contains(COCOS2D-X_MODULES,CocosDenshion) {
                        SHAREDLIBS_DIR += $$COCOS2DX_ROOT/CocosDenshion/third_party/fmod/lib64/api/lib
            SHAREDLIBS += -L$$SHAREDLIBS_DIR -lfmodex64
        }

        DEFINES += NDEBUG

                SHAREDLIBS += -L$$COCOS2DX_ROOT/lib/linux/release -Wl,-rpath,$$COCOS2DX_ROOT/lib/linux/release

                STATICLIBS += $$COCOS2DX_ROOT/lib/linux/release/libbox2d.a

        SHAREDLIBS += -lcocos2d -lrt -lz
        SHAREDLIBS += -lfreetype -lcurl -lGL -lGLEW
#        SHAREDLIBS += -lxml2 -lpng -ljpep -ltif\f

        SHAREDLIBS += -lcocosdenshion


    SHAREDLIBS += -Wl,-rpath,$${SHAREDLIBS_DIR}
    SHAREDLIBS += -Wl,-rpath,$$STATICLIBS_DIR

    LIBS += $${STATICLIBS}
    LIBS += $${SHAREDLIBS}
} 

INCLUDEPATH += $${COCOS_INCLUDE_DEPEND_PATH}
DEPENDPATH += $${COCOS_INCLUDE_DEPEND_PATH}

我的 main.cpp 文件:

  #include "../Classes/AppDelegate.h"
#include "cocos2d.h"
#include "CCEGLView.h"

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string>

#include "../Classes/AppDelegate.h"

USING_NS_CC;

// 500 is enough?
#define MAXPATHLEN 500

int main(int argc, char **argv)
{
    // get application path
    int length;
    char fullpath[MAXPATHLEN];
    length = readlink("/proc/self/exe", fullpath, sizeof(fullpath));
    fullpath[length] = '\0';

    std::string resourcePath = fullpath;
    resourcePath = resourcePath.substr(0, resourcePath.find_last_of("/"));
    resourcePath += "/../../Resources/";

    // create the application instance
    AppDelegate app;
    CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setFrameSize(800, 480);

    return CCApplication::sharedApplication()->run();
}

项目编译正常,没有错误,但是当应用程序运行时,黑屏窗口出现并在下一刻消失。我认为 run() 方法返回-1。控制台输出打印我这个:

cocos2d-x debug info [Ready for GLSL]
cocos2d-x debug info [Ready for OpenGL 2.0]

我尝试在 Ubuntu 12.04 上运行我的项目。谁能知道我做错了什么?

===== 编辑 应用代理:

#include "AppDelegate.h"
#include "HelloWorldScene.h"

USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director

    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

但我认为,来自 appdelegate 的代码永远不会执行:/

【问题讨论】:

    标签: c++ opengl ide qt-creator cocos2d-x


    【解决方案1】:

    这部分看起来不错, 检查 AppDelegate::applicationDidFinishLaunching() 方法,这就是应用程序实际启动的地方,您也可以在上述方法中设置资源路径变量,因为到那时什么都不会被访问..

    【讨论】:

    • 如果您需要更多信息,请粘贴 AppDelegate::applicationDidFinishLaunching() 方法中的代码
    • AppDelegate.cpp 包含在问题中 :) 我需要更多信息 :P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    相关资源
    最近更新 更多