2014-10-02 166 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)