我已经制作了一个使用 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中删除精灵。
就我而言,我确实喜欢跟随。每当绘图完成(touchbestart,touchmove,touchend)时,我都会将RenderTexture的图像保存在数组中。然后,当我单击撤消按钮时,我从数组中获取图像并在 RenderTexture 上访问它。我希望它对你有所帮助。