如何使用cocos2d-x中的CCRenderTexture实现撤消重做功能以绘制平滑线

时间:2014-03-03 11:35:05

标签: ios iphone cocoa-touch cocos2d-x

我使用CCSprite和CCRenderTexture创建了绘图功能。像

    Paint *paintColor=Paint::create("texture1@2x.png");
    draw=true;

    CCPoint end = touch->getPreviousLocationInView();
    end = CCDirector::sharedDirector()->convertToGL(end);

    target->begin();

    float distance = ccpDistance(start, end);

    for (int i = 0; i < distance; i++)
    {
        paintColor->color=globalColor;
        paintColor->setColor(paintColor->color);
        paintColor->scale=globalScale;
        paintColor->setScale(paintColor->scale);
        paintColor->opacity=globalOpacity;
        paintColor->setOpacity(paintColor->opacity);


        float difx = end.x - start.x;
        float dify = end.y - start.y;
        float delta = (float)i / distance;

        CCPoint p=ccp(start.x + (difx * delta), start.y + (dify * delta));

        paintColor->originalPosition=p;
        paintColor->setPosition(paintColor->originalPosition);

        tempPath.path.push_back(p);
        tempPath.color=globalColor;
        tempPath.scale=globalScale;
        tempPath.opacity=globalOpacity;


        paintColor->visit();
}

但我想要撤消功能,并希望从CCRenderTexture中删除最后的绘制纹理。任何人都可以帮我制作这个功能。有没有从CCRenderTexture中删除精灵的方法。

1 个答案:

答案 0 :(得分:0)

在我的情况下,我确实喜欢跟随。 每当完成绘图(touchbegan,touchmove,touchend)时,我都会将RenderTexture的图像保存在一个数组中。 然后,当我点击撤消按钮时,我从数组中取出图像并在RenderTexture上访问它。 我希望它可以帮助你。