1920x1080 JPEG not filling whole screen

1920x1080 JPEG not filling whole screen



I am new to Cocos C++. I have been using App Game Kit 2 previously and have now ported my C++ code across to Cocos. I hope to stick with Cocos from now on.

Although I have an issue.

My monitor is set at 1920x1080. I have a white background JPEG which is 1920x1080.

In AGK2, I display this image at position 0,0 (top left hand corner) and it fills my whole screen.

In Cocos (when I centre it), it seems to be smaller and it is displayed with black borders around it? i.e. it does not fill the screen.

My resolution is set as:

static cocos2d::Size designResolutionSize = cocos2d::Size(1920, 1080)

And I am in full screen mode:

glview = GLViewImpl::createWithFullScreen(“CocosGame”)

I get the screen size as:


and as expected it returns Size.width=1920 and Size.height=1080

I get the origin as:


and again as expected it returns Vec2(0, 0)

I set the x position as:

size.width / 2 + origin.x

and y position as:

size.height / 2 + origin.y

So basically I do:

setxy(size.width / 2 + origin.x, size.height / 2 + origin.y)

which translates to:

sprite->setPosition(Vec2(x, y))

This should place the JPEG in the middle of the screen and fill out the whole display, or am I wrong?

I am literally running my code almost as the HelloWorldScene template.

Anyone got an idea?


Try set anchor point 0,0 and position 0, 0


Thanks, but I tried that and yes it displays the image at the very bottom left hand corner, but again my image appears smaller than1920x1080, The black background is still showing on top and on the right hand side of the image.

I have confirmed that Cocos agrees my sprite is indeed 1920x1080 by using getOriginalSizeInPixels().

So what is happening with the render?


Can you show screenshot?


You’ve defined a variable for the DesignResolution… but did you set it? glview->setDesignResolution(…);

getVisibleSize() returns the screenSize of the device (opengl viewport). not the design Resolution


Yes, I am using the template AppDelegate.cpp.

glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER)


I just tried rendering a bigger image of size 2000x1200, which is bigger than the screen. Again, this was trimmed on the left and right hand sides, so I get the black background on each side.


Does your monitor support 1920x1080 resolution?
Can you show screenshot?


Woo hoo! I got it to work! Go … Cocos!

This did the trick:

sprite->setContentSize(Size(1920, 1080));

And yes my PC is an all-in-one at 1920x1080.

Thanks guys, hooray for Intellisense!

Still, if anyone can elaborate on this issue, I would be so grateful.


FYI, I was curious, so I just tried sprite->getContentSize() to see what Cocos thought the size was of my image, and it reported:

width=1799.999878, height=1012.499939



But my image is definitely 1920x1080 because I created it in Paint, and Windows Explorer says 1920x1080 when I hover over the file.

Like I said before, App Game Kit 2, used it fine.

Actually I think all my sprites in my game have this happening to them.

Cocos knows the original size, but it stores the content size of them as smaller?

Has this anything to do with multi-resolution support?

I still think Cocos should not be doing this as my screen device size is 1920x1080.

I would understand if I were rendering my game onto a lower resolution device.


explicitly setting the ContentSize of Sprites is not the right way.
Maybe you should also check the contentScaleFactor.


Here is problem:

What cocos2d version do you use?


Can you post the image or PM it to me?


I want to add:
I have a simple 20x20px picture. Setting it to the screen size as a background will result in a small uncovered border around the screen.

Setting something like: screenWidth+2, screenHeight+2 will fix it.


Try this



Hey, yes, I have uncovered the mystery. MuratAlbayrak was correct.

It was the director->setContentScaleFactor() setting.

The design resolution was 1920x1080 (which I updated from the default 480x320) and the medium resolution was 1024x768 (which is the default in AppDelegate.cpp).

The line in ApDelegate.cpp:

if (frameSize.height > mediumResolutionSize.height)
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));

set it to 1.066667.

I want the setting to be 1.0, so temporarily I have updated the medium resolution to 1920x1080 and all is fine.

I won’t set the content size of my sprites now, thank goodness!


Nice, you can mark this thread as solved


Do you mean I have to set something to update this thread?

I can’t see any button.


Yes, on previous your post select checkbox