I’m porting a project of mine from cocos2d-html5 to cocos2d-x, and have found some strange behaviour with the rendertexture class. Anything I draw to the rendertexture using visit() appears stretched, unless the rendertexture’s size is the same as the visible screen. The smaller I make the rendertexture, the larger the sprites drawn to it with visit() appear to be. Some example code:
// create renderTexture, and sprite to draw onto it auto renderTexture = RenderTexture::create(512,512); renderTexture->setPosition(0, 0); renderTexture->beginWithClear(0, 0, 0, 255); auto drawSprite = Sprite::create("draw.png"); drawSprite->setPosition(0, 0); drawSprite->visit(); renderTexture->end(); // create sprite using rendertexture auto rendTexSprite = Sprite::create(); rendTexSprite->setTexture(renderTexture->getSprite()->getTexture()); rendTexSprite->setTextureRect(Rect(0, 0, rendTexSprite->getTexture()->getContentSize().width, rendTexSprite->getTexture()->getContentSize().height)); this->addChild(rendTexSprite);
This causes the sprite drawn to the rendertexture (drawSprite) to appear stretched in the x axis. If the renderTexture is created with the same dimensions as the visible screen (e.g. 900x640), then the problem goes away, but I’m left with a huge texture.
Any ideas greatly appreciated