I want to be able to pick multiple tiles from my tilesheet and “stamp” them onto a new texture which will become a sprite. I can do it once, but when I try to do it a second time the first stamp is erased from the texture. The plan is to do all of this in a loop when it’s done (things are hardcoded right now).
Or should is it better (or faster) to manipulate the texture data as discussed here?
Is it possible to "erase" some pixels from a sprite?
Here’s the code code I’ve been testing with:
// src is a sprite
Rect rectStart = Rect((colStart * TILE_SIZE) + offset.x, (rowStart * TILE_SIZE + offset.y), 16, 16);
auto texture = RenderTexture::create(w, h, src->getTexture()->getPixelFormat());
auto stamp = RenderTexture::create(16, 16, src->getTexture()->getPixelFormat());
stamp->clear(0, 0, 0, 0);
stamp->begin();
src->setFlipY(true);
src->setPosition(-rectStart.origin.x, -rectStart.origin.y);
src->visit();
stamp->end();
texture->clear(1.0f, 0, 0, 1.0f);
texture->begin();
stamp->setPosition(8, 8);
stamp->visit(Director::getInstance()->getRenderer(), this->getParentToNodeTransform(), FLAGS_TRANSFORM_DIRTY);
texture->end();
Rect rectEnd = Rect((colMid * TILE_SIZE) + offset.x, (rowMid * TILE_SIZE + offset.y), 16, 16);
stamp->clear(0, 0, 0, 0);
stamp->begin();
src->setPosition(-rectEnd.origin.x, -rectEnd.origin.y);
src->visit();
stamp->end();
texture->begin();
stamp->setPosition(24, 8);
stamp->visit(Director::getInstance()->getRenderer(), this->getParentToNodeTransform(), FLAGS_TRANSFORM_DIRTY);
texture->end();