cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

Texture2D created with RenderTexture disappear while changing parent position along X axis #11745

Open smoke91 opened 9 years ago

smoke91 commented 9 years ago

I created tile map with tile layers and objects layer. After parsing xml i want to get all objects, create physics object and render textures for them based on tile layer with this code:

    auto renderTexture = RenderTexture::create(bodySize.width, bodySize.height);
renderTexture->beginWithClear(0, 0, 0, 0);
renderTexture->retain();
for (auto tilePosition : tilesPosition)
{
    Sprite* tileSprite = tileLayer->getTileAt(tilePosition);
    Vec2 tilePos = tileSprite->getPosition();
    tileSprite->setPosition(Vec2(tilePos.x - minX, tilePos.y - minY));
    tileSprite->retain();
    tileSprite->visit();
    tileSprite->setPosition(tilePos);
}
renderTexture->end();
Vec2 renderTexPosition = helper->getRenderTexturePositionFromTilesRange(tileRange, minX, minY);
Texture2D* texture = renderTexture->getSprite()->getTexture();
texture->retain();
bodyNode->retain();
bodyNode->setFlippedY(true);
bodyNode->setPhysicsBody(body);
bodyNode->setPosition(bodyPosition);
    return bodyNode;

Next I added created Sprites to Scene. They are rendered correctly, but when I moving scene position: with Follow action, textures being dissapear the further I move scene.

smoke91 commented 9 years ago

Workaround: i've added sprites to transparent layer and layer to scene, now it's working workaround works also for: #11743