2014-10-02 27 views
0

我想创建一个类似于不碰块的游戏。当我创建块,我希望让雪碧可以init.code是在这里:关于Sprite :: init()在cocos2dx中的错误

 #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; 
} 

但是当我编写这一点,我foud雪碧)错误::初始化(; VS2012告诉我“不要访问保护成员(在cocos2d:雪碧类的声明)”

回答

1

你正在编写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)