I'm just training cocos2d-x.
Now,I tryed to create sprite on display using CCSprite class.
I wrote the code as follows.
Characters Class
class characters : public cocos2d::CCSprite{
public:
void setRect(CCPoint point);
CCRect getRect();
void setTag(int x,int y);
int getTag();
void setDirection(int num);
int* getDirection();
bool isTouchPoint(CCPoint point);
void animation(characters *chara,int num);
private:
CCRect m_rect;
int m_tag;
};
bool HelloWorld::init(){
for(int i=0;i<9;i++){
characters *chara = new characters;
chara->autorelease();
chara->create("char04x2.png");
x = Indexes[i]%HORIZONTAL_AXIS; //Indexes is cell number on display
y = Indexes[i]/HORIZONTAL_AXIS;
CCPoint point = ccp(MARGIN_WIDTH + PIPE_WIDTH * x,MARGIN_HEIGHT + PIPE_HEIGHT * y);
chara->setPosition(point);
chara->setRect(point);
chara->setTag(x,y);
this->addChild(chara,1);
}
}
But,this code is wrong.
It stops in CC_NODE_DRAW_SETUP() of void CCSprite::draw(void) method.
Error message is
Cocos2d: Assert failed: No shader program set for this node Assertion failed: (getShaderProgram()), function draw, file /Users/nyoronyoro-kun/Desktop/cocos2d-x/cocos2dx/sprite_nodes/CCSprite.cpp, line 554.
When I replaced create method with initWithFile method,error don't appear.
Why this error appeared?