Cocos2d-x 3.1.1 Learning Log 15 -- difference between getContentSize and getContentSizeInPixels

Source: Internet
Author: User

Cocos2d-x 3.1.1 Learning Log 15 -- difference between getContentSize and getContentSizeInPixels
In the cocos2d-x, getContentSize is the size of the logical point, while getContentSizeInPixels is the size of the pixel. The ing between pixel points and logical points is: logical point size = pixel size/contentScaleFactor.

If a high-resolution platform (such as iPhone 4) uses a non-high-resolution image resource and sets contentScaleFactor to 1.0, the Core Animation compositor of IOS automatically scales out non-high-resolution resources for adaptation, make it have the same visual effect on non-high-resolution and high-resolution devices.

If you set contentScaleFactor to a value between (1.0, 2.0], the system uses the tensile value you set.

The cocos2d-x provides interfaces to set contentScaleFactor: CCDirector: setContentScaleFactor.

After learning about the IOS resolution, Let's explain the cause of the problem.

Problem 1: Because enableRetinaDisplay (false) is set and contentScaleFactor is 1.0, the image will be treated as a non-HD resource, and the horizontal and vertical resolutions will be stretched twice when displayed.

Question 2: Because enableRetinaDisplay (true) is set and contentScaleFactor is 2.0, the image is displayed as the original pixel size. However, setPosition is used to set the location, which is the logical location. Because the previous position was set based on the screen size of 800*480, when contentScaleFactor is 2.0, it is equivalent to 1600*960 pixels for the reference screen, therefore, the location of the genie is incorrect.


Logic points are recommended.


Next we will parse the coordinates and paste the source code directly:
CCPoint CCDirector: convertToGL (const CCPoint & uiPoint)
{
CCSize s = m_obWinSizeInPoints;
Float newY = s. height-uiPoint. y;

Return ccp (uiPoint. x, newY );
}

CCPoint CCDirector: convertToUI (const CCPoint & glPoint)
{
CCSize winSize = m_obWinSizeInPoints;
Float oppositeY = winSize. height-glPoint. y;

Return ccp (glPoint. x, oppositeY );
}

The X direction of the two coordinates is not changed, but only the Y direction is changed. In cocos2d, the default GL coordinate system is used, that is, the origin ccp (0.0f.0.0f) in the lower left corner, which is increased up in the Y direction and X is increased horizontally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.