关于cocos2dx中Sprite :: init()的错误

时间:2014-10-02 02:43:44

标签: cocos2d-x

我想创建一个像不要触摸块的游戏。当我创建一个Block时,我想让Sprite可以在init.code这里:

        #pragma once
        #include<iostream>
        #include "cocos2d.h"
        #include "Block.h"
        USING_NS_CC; 

Block* CreateWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)
{
    auto b = new Block();
    b->initWithArgs(color, size, label, fontsize, textcolor);
    b->autorelease();
    return b;

}


bool initWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)
{

    Sprite::init();
    return true;
}

但是当我编码时,我在Sprite :: init()中输入错误; VS2012告诉我“无权访问受保护的成员(在cocos2d :: Sprite类声明中)”

1 个答案:

答案 0 :(得分:2)

您正在编写C函数:

Block* CreateWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)
bool initWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)

在C ++类中,方法需要以类的名称为前缀,例如假设类为MySprite

Block* MySprite::CreateWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)
bool MySprite::initWithArgs(Color3B color, Size size, std::string label, float fontsize, Color4B textcolor)