Hii, hope you all are fine.
I am creating an Android project and using an image for the background and scaling it to the size of the screen, but it results as 180 degree rotated image.
here is my code…
I have scaled another image with the same code and it worked fine for that image. I don’t know why this strange thing is happening with this image.
I am attaching the image…
Post an image of what you expect to see, and another of what you’re actually seeing, to get a better understanding of what the problem is.
Also, are you aware that the RenderTexture sprite is actually flipped vertically? You have to flip it back before using it via Sprite:::setFlippedY();.
Try to adding that call to the RenderTexture sprite and see if it helps, like this:
or alternatively, what may work is to flip the sprites you’re adding to the RenderTexture before calling visit on them, and remember to flip them back if you’re still using them somewhere else.
auto backgroundRoad = Sprite::create("background.png");
auto brWidth = backgroundRoad->getContentSize().width;
auto brHeight = backgroundRoad->getContentSize().height;
backgroundRoad->setScale(vsWidth/brWidth, vsHeight/brHeight);
backgroundRoad->setPosition(Point(vsWidth/2, vsHeight/2));
backgroundRoad->setFlippedY(true);
auto renderTextureForRoad = RenderTexture::create( vsWidth, vsHeight, PixelFormat::RGBA8888 );
renderTextureForRoad->begin();
backgroundRoad->visit();
renderTextureForRoad->end();
backgroundRoad->setFlippedY(false);
road = Sprite::createWithTexture(renderTextureForRoad->getSprite()->getTexture());
road->setPosition(vsWidth/2, vsHeight/2);
this->addChild(road);
Ohh okay, I didn’t know this before. Can you please explain to me why it is so or if there is a reference link by which I can come to know about it. And you got my problem right, I was getting vertically flipped image.
like this:
One more thing, setFlippedY() function is not available for RenderTexture, it is available for normal sprite, so I have to apply it on road sprite( for my example).
And can’t we just add that flip function in RenderTexture code itself so that we will get correct oriented image without flipping it?