Hello,
I am using 2.0.4 Multi resolution functionality and i must say it is a great enhancement to cocos2dx…
I need one help for kResolutionShowAll
In my project it is ok in ipad retina and non retina…
In Android devices in most of the devices it is scaling based on device resolution and keeping all resources in mid screen which is just as expected…
So in android is there any way to put one background image to cover whole screen and other component as that kResolutionShowAll…
Just want to cover blank part of the screen in such devices…
Thank you very much for the response @Minggo Zhang…
I have tried to put big image but as per this policy that big image also scales to fit its edges and that blank part left as it is…
For temporary solution i have changed displayResolution Policy in android to some different value (960 x 640) but that only reduced some of the blank part but not fitting in the real solution…
So still trying some solution…
I’ve tried kResolutionShowAll too, Viraj is right. There is no way to fill the black borders with an image… It should be great and very practically to have possibility to cover the side border with a custom background…
Also seeking this functionality. I have a background that scales nicely, and would like to stretch it over the whole screen and letterbox the content.
Are there any other solutions? Or stuck with black bars / letterboxing everything?
Background image is set to full screen scale (set my scaleX/Y really high to stretch as far as possible)
Design res is 320x480
Device res is 640x1136 (iPhone 5)
So what we’re looking for is a background that scales the full screen (i.e. outside of design resolution aspect), while the content is still tied to the design resolution.
At the moment there’s no way to specify a background that scales the whole device rather than just the aspect.
It’d be nice to be able to position the content to the top / middle or bottom of the screen as well dependant on configuration.
I have quick solution. It’s not perfect but it’s working in my game. I added new CCSprite object to CCDirector to draw background. So, add two new members to CCDirector.h:
void setBackground(const char *bg); // to public section
CCSprite* m_Background; // to private section
Then add implementation of setBackground to CCDirector.cpp:
Finally, insert drawing code for m_Background in CCDirector. The best place should be immediately above kmGLPushMatrix in CCDirector::drawScene:
// Draw the Scene
void CCDirector::drawScene(void)
{
// calculate "global" dt
calculateDeltaTime();
//tick before glClear: issue #533
if (! m_bPaused)
{
m_pScheduler->update(m_fDeltaTime);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
if (m_pNextScene)
{
setNextScene();
}
if (m_Background) {
ResolutionPolicy rp = m_pobOpenGLView->getResolutionPolicy();
CCSize rs = m_pobOpenGLView->getDesignResolutionSize();
if (rp == kResolutionShowAll) {
CCSize cs = m_Background->getContentSize();
m_pobOpenGLView->setDesignResolutionSize(cs.width, cs.height, kResolutionNoBorder);
m_Background->visit();
m_pobOpenGLView->setDesignResolutionSize(rs.width, rs.height, rp);
}
}
kmGLPushMatrix();
// draw the scene
if (m_pRunningScene)
{
m_pRunningScene->visit();
}
// draw the notifications node
if (m_pNotificationNode)
{
m_pNotificationNode->visit();
}
if (m_bDisplayStats)
{
showStats();
}
kmGLPopMatrix();
m_uTotalFrames++;
// swap buffers
if (m_pobOpenGLView)
{
m_pobOpenGLView->swapBuffers();
}
if (m_bDisplayStats)
{
calculateMPF();
}
}