0

我有一个继承自 CCNode 的类。HcharacterDrawnode 包含一组 StrokeDrawnode,这是另一个自定义 CCNode。现在我将 (m_HDrawnode)HcharacterDrawnode 添加到图层并运行Action。

CCAction* place = CCMoveTo::create(2.0,ccp(0,0));   
m_HDrawnode->runAction(place);

但是什么也没发生。我检查了一些网页。有人说它可能与m_bRunning,但是我找不到设置这个变量的地方。

HcharacterDrawnode.h

class HcharacterDrawnode : public CCNode
{
public:
    HcharacterDrawnode();
    ~HcharacterDrawnode();
    CREATE_FUNC(HcharacterDrawnode);
    virtual bool init();
    virtual void onEnter();
    virtual void onExit();
    virtual void draw();

    void addPoint(CCPoint point);

    void addStroke(Stroke s);

    void removeLastStroke();

    CC_SYNTHESIZE_RETAIN(CCArray*,strokeDrawlist,StrokeDrawnodeList);
private:

};

HcharacterDrawnode.cpp

#include "HcharacterDrawnode.h"

HcharacterDrawnode::HcharacterDrawnode():strokeDrawlist(NULL)
{
}

HcharacterDrawnode::~HcharacterDrawnode()
{
    CC_SAFE_RELEASE(strokeDrawlist);
}

void HcharacterDrawnode::onEnter(){
    CCNode::onEnter();

}

void HcharacterDrawnode::onExit(){
    CCNode::onExit();
}

bool HcharacterDrawnode::init(){
    this->setStrokeDrawnodeList(CCArray::create());
    return true;
}

void HcharacterDrawnode::draw(){
    CCObject* ob;
    CCARRAY_FOREACH(strokeDrawlist,ob){
        ((StrokeDrawnode*)(ob))->draw();
    }
}

void HcharacterDrawnode::addPoint(CCPoint point){
    StrokeDrawnode* t = (StrokeDrawnode*)(strokeDrawlist->objectAtIndex(strokeDrawlist->count()-1));
    t->addPoint(point);
}

void HcharacterDrawnode::addStroke(Stroke s){
    strokeDrawlist->addObject(StrokeDrawnode::create(s));
}

void HcharacterDrawnode::removeLastStroke(){
    strokeDrawlist->removeLastObject();
}

描边节点.h

class StrokeDrawnode : public CCNode
{
public:
    StrokeDrawnode();
    StrokeDrawnode(Stroke stro);
    ~StrokeDrawnode();
    static StrokeDrawnode* create(Stroke stro);
    Stroke stroke;
    ccColor4B mcolor;

    virtual void onEnter();
    virtual void onExit();

    virtual void draw();
    int visibleIndex;
    void addPoint(CCPoint point);
private:

};

描边节点.cpp

#include "StrokeDrawnode.h"

StrokeDrawnode::StrokeDrawnode()
{
}

StrokeDrawnode::StrokeDrawnode(Stroke stro){
    this->stroke = stro;
}

void StrokeDrawnode::onEnter(){
    CCNode::onEnter();
}

void StrokeDrawnode::onExit(){
    CCNode::onExit();
}

StrokeDrawnode* StrokeDrawnode::create(Stroke stro){
    StrokeDrawnode* pRet = new StrokeDrawnode(stro);
    if (pRet && pRet->init())
    {
        pRet->autorelease();
        return pRet;
    }else{
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}

StrokeDrawnode::~StrokeDrawnode()
{

}

void StrokeDrawnode::draw(){
    //CCLog("StrokeDrawnode::draw");
    glLineWidth(6.0f);                  
    ccDrawColor4F(0,0,0,1);             
//  glEnable(GL_LINE_SMOOTH);
    CCPoint pre = stroke.pointList[0];
    for (int i = 1; i< stroke.pointCount; i++)
    {
        ccDrawLine(pre,stroke.pointList[i]);
        pre = stroke.pointList[i];
    }
//  glDisable(GL_LINE_SMOOTH);
}

void StrokeDrawnode::addPoint(CCPoint point){
    this->stroke.addPoint(point);
}
4

1 回答 1

0

您绘制了您的 StrokeNode,但您忘记为 HcharacterDrawnode 调用 CCNode::draw() 函数:

void HcharacterDrawnode::draw(){
    CCNode::draw();
    CCObject* ob;
    CCARRAY_FOREACH(strokeDrawlist,ob){
        ((StrokeDrawnode*)(ob))->draw();
    }
}

此外,如果您在班级中覆盖 init() ,则应调用父母的 init :

bool HcharacterDrawnode::init(){
if(!CCNode::init())
    return false;

this->setStrokeDrawnodeList(CCArray::create());
return true;

}

于 2014-04-03T10:19:24.630 回答