ResolutionPolicy SHOW_ALL with touch enabled borders FrameBuffer Camera

Hi,

my game runs in 4:3 and I use ResolutionPolicy::SHOW_ALL to have correct aspect ratio but if I do that, I am not able to get touch events on the left and right black border because it is outside of the GLView.

I tried to create a layer as parent called gameLayer and placed my framebuffer sprite centered in it and a camera with a calculated viewport. But my output is a bit distorted.

    mGameLayer = LayerColor::create(Color4B(255, 0, 0, 255));
this->addChild(mGameLayer, 0, 0);

auto lWinSize = Director::getInstance()->getWinSizeInPixels();

// create FrameBuffer
auto lFrameBufferSize = Size(320, 240);
auto lFrameBuffer = experimental::FrameBuffer::create(1, lFrameBufferSize.width, lFrameBufferSize.height);
//fbo->setClearColor(Color4F(255, 255, 255, 0));
lFrameBuffer->setClearColor(Color4F(0, 255, 0, 255));
auto lRenderTarget = experimental::RenderTarget::create(lFrameBufferSize.width, lFrameBufferSize.height);
auto lRenderTargetDepthStencil = experimental::RenderTargetDepthStencil::create(lFrameBufferSize.width, lFrameBufferSize.height);
lFrameBuffer->attachRenderTarget(lRenderTarget);
lFrameBuffer->attachDepthStencilTarget(lRenderTargetDepthStencil);
lFrameBuffer->getRenderTarget()->getTexture()->setAliasTexParameters();

// create texture from FrameBuffer
auto lFrameBufferSprite = Sprite::createWithTexture(lFrameBuffer->getRenderTarget()->getTexture());
lFrameBufferSprite->setPosition(lWinSize.width / 2, lWinSize.height / 2);
lFrameBufferSprite->setScale(lWinSize.height / 240.0f); // zoom into to have full height off screen
lFrameBufferSprite->setFlippedY(true);
mGameLayer->addChild(lFrameBufferSprite);

// add sprites
sprite2 = Sprite::create("cut3x.png"); // resolution is 960x720
int fboWidth = lFrameBufferSprite->getTexture()->getContentSizeInPixels().width * 3;
int fboHeight = lFrameBufferSprite->getTexture()->getContentSizeInPixels().height * 3;
sprite2->setPosition(fboWidth / 2, fboHeight / 2);
sprite2->getTexture()->setAliasTexParameters();

// apply shader to FrameBuffer sprite
InitShader(lFrameBufferSprite);

// create camera and set new viewport to zoom in and show picture with maximal height
auto camera = Camera::create();
camera->setCameraFlag(CameraFlag::USER1);
camera->setDepth(-1);
camera->setFrameBufferObject(lFrameBuffer);
float viewPortRectWidthRatio = static_cast<float>(lWinSize.width) / static_cast<float>(960);
float viewPortRectHeightRatio = static_cast<float>(lWinSize.height) / static_cast<float>(720);
float viewPortW = ceilf(viewPortRectWidthRatio * (float)1000.0) / (float)1000.0;
float viewPortH = ceilf(viewPortRectHeightRatio * (float)1000.0) / (float)1000.0;
experimental::Viewport lViewPort = experimental::Viewport(0, 0, viewPortW, viewPortH);

camera->setViewport(lViewPort);
mGameLayer->addChild(camera);

Any advice how I can or should do this`? :astonished:

Thank you!

At last, it would be helpful to know if it is possible to capture touch settings in black border area, if ResolutionPolicy is set to SHOW_ALL.

My only suggestion is not to use SHOW_ALL.

If you are completely satisfied with SHOW_ALL, then you can replace it with FIXED_HEIGHT or FIXED_WIDTH (depending on the orientation and your Design Resolution)
and you will get the mostly same effect, but

  1. the black bolders will be touchable
  2. the VisibleOrigin will always be (0, 0)
  3. the height or the width (depending on what you use, FIXWD_HEIGHT or FIXED_WIDTH) of your Design Resolution will be recalculated depending on the current device.

Thank you for your answer. I think it matchs my current attempt.

You are welcome! :slight_smile: