Errors while building class cocos2d-x

前提是你 提交于 2019-12-12 23:33:32

问题


I added class GraphicsScene.h:

#pragma once

#include "cocos2d.h"

class GraphicsScene : public cocos2d::Layer
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
    CREATE_FUNC(GraphicsScene);
};

Then

#include "GraphicsScene.h"

USING_NS_CC;

Scene* GraphicsScene::createScene()
{
    auto scene = Scene::create();
    auto layer = GraphicsScene::create();
   scene->addChild(layer);

    return scene;
}

bool GraphicsScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

    auto sprite = Sprite::create("HelloWorld.png");
    sprite->setPosition(0, 0);

    this->addChild(sprite, 0);

    return true;
}

Then I added in AppDelegate instead of usual HelloWorld::createScene():

auto scene = GraphicsScene::createScene();
    // run
director->runWithScene(scene);

I added name of the class in Android.mk.

These are errors

What I m doing wrong? How to create class?


回答1:


Everything seems good.

I guess you edited wrong Android.mk file. Please check what Android.mk file are you editing ?

The one in proj.android or the one in proj.android-studio?

When compiling using --android-studio tag, you are compiling the project inside proj.android-studio, not proj.android.

cocos compile -p android --android-studio

You're not using include guard in GraphicsScene.h. Use include guard to avoid the same header file being included multiple times.

EDIT

remove static keyword from createScene method definition inside GraphicsScene.cpp

static Scene* GraphicsScene::createScene()
{
    auto scene = Scene::create();
    auto layer = GraphicsScene::create();
    scene->addChild(layer);
    return scene;
}

EDIT 2

Android.mk of proj.android-studio

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   ../../../Classes/HelloWorldScene.cpp \
                   ../../Classes/GraphicsScene.cpp   --> Path is wrong for this file

so change this to ../../../Classes/GraphicsScene.cpp



来源:https://stackoverflow.com/questions/43431586/errors-while-building-class-cocos2d-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!