contentScaleFactor not working correctly

contentScaleFactor not working correctly
0.0 0

#43

ResolutionPolicy has effect here in my case. As you can see for 480 * 800 data below,

dpi = 240
Content Scale Factor: 1.000000
FrameSize HW: 480.000000 800.000000
CustUtils: screenHeight, screenWidth: 480.000000, 800.000000
CustUtils: designScreenHeight, designScreenWidth: 720.000000, 1280.000000 (This is I am setting in CustUtils.cpp, Not glview->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER):wink:
CustUtils: scaleX, scaleY: 1.000000, 0.666667
Bounding HW= 480.000000 853.333374
Image HW= 720.000000 1280.000000

Here by default image size is , 1280 * 720 but getting scaled. After scaling image size is 853 * 480. Since 853 > 800, image is getting cropped width wise.

Though contentScaleFactor is by default 1, but since my previous designResolution was 1280 * 720, it was not working correctly. Do not get confused by glview->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER); with mu CustUtils.cpp designResolution HW.

Whatever is happening right now is the thing I wanted to achieve. :slight_smile:


#44

Yes. That is being used in SplashScreen.cpp.

The more I start developing, I will find out more. Will keep you updated.


#45

I meant that if you never called setDesignResolutionSize(), then your design resolution is equal to the frame size and ResolutionPolicy = NO_POLICY.
And if you use glview->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER), then even though you specified a policy, it is like you did not specify anything in the end. The result is the same.

In the end, you can delete that block of code, nothing will change. :slight_smile:


#46

No Border - “The entire application fills the specified area, without distortion but possibly with some cropping, while maintaining the original aspect ratio of the application.”

As you can see in my case -

  • Application is filling the specified area.
  • Cropping is happening.
  • Original AR is being maintained.

#47

Where did you get this quote?

We’re talking about Case 4, right?

By the way, I really like how you write your posts - in detail and with screenshots.


#48

Go to - http://www.cocos2d-x.org/wiki/Multi_resolution_support#No-border

No no. All my Test Cases are invalid because of wrong use. I have not posted the successful ones except one. Check

Big Thanks. :smiley:


#49

The quote is not true.

NO_BORDER - The design resolution will be scaled to fit into the screen size (the frame size), and there will be no distortions, and there will be no black borders, but perhaps a part of the design resolution will not be visible (if the aspect ratio of the design resolution is not equal to the aspect ratio of the frame).


#50

This is what I said

It’s also saying the same thing from http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation-

According to the width and height of screen and design resolution to determine the scale factor, choose the larger one as the scale factor. This can make sure that one axis can always fully display on screen, but another may scale out of the screen.

Same same I think. And that is happening for my case. Look at this - Multi-resolution code in the default template


#51

The application and design resolution are different things. If you use NO_BORDER and use setContentScaleFactor() incorrectly, then you can get both black borders and the wrong scale.
ResolutionPolicy only works with a design resolution.

Yes, I read your post in other topic in parallel.
But now my mind is too tired and wants to sleep. I will read it carefully tomorrow, okay?


#52

We will add to our docs a lot of info from this thread. How would you all feel about proof-reading a draft once complete? I’ll be working on this over the next few days.


#53

No probs. :slight_smile:


#54

That would be great. Must add snaps for better understanding with some real time data. :slight_smile:


#55

of course, graphics are very helpful to understanding.


#56

I don’t mind.


#57

If you still have questions, please write it like
code + result + question.
I think we considered different cases in the last posts.


#58

I do not know if this is useful, but I think that a good plan to explain the concept to someone is

  • There are many different screen resolutions with different aspect ratios.
    This raises many questions.
    What screen resolutions should we use to create graphics resources? What coordinates should we use to set the position? How to scale resources?

->

  • What is the design resolution and how one line of code answers these questions.
    A few code examples with setDesignResolutionSize(), but without setContentScaleFactor().
    Only one set of graphics resources.

->

  • Why is it a good idea to have multiple sets of graphics resources.
    A few code examples with setDesignResolutionSize() and setContentScaleFactor() and setSearchPath().

->

  • An alternative way. Do not use design resolution, use only setContentScaleFactor().
    A few code examples.

->

  • More complex cases.

#59

May be. I was not talking about my Test Cases 1-4 today. Because I implemented my way at yesterday night.


#60

If you mean Utils.cpp, then my idea was that if you use it, then you do not need to use glview->setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER). But of course you can do this if you want.

The reason I mentioned glview->setDesignResolutionSize(1280.0f, 720.0f, ResolutionPolicy::NO_BORDER) is that I noticed that your implement the same scaling logic that NO_BORDER. But this is not a full equivalent, I wrote about the difference here.
And I edited this post to avoid confusion.

By the way, if you use Utils.cpp, and do not use setDesignResolutionSize() (or use it like setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER)), then you do not need to worry about visibleOrigin, and getVisibleSize() will always return frame size.

Do we agree now? :slight_smile:


#61

I have not tested without setDesignResolution. I want to use the default visibleOrigin or getVisibleSize(). May be you are right. When I was using glview->setDesignResolutionSize(1280.0f, 720.0f, ResolutionPolicy::NO_BORDER), you can see from Test Case 4, my output was

Bounding HW= 675.000000 1200.000000

This is not equal to frameSize or designResolutionSize. That’s why I got confused.

So, I have not tested without these two. What I wanted, I got that, that’s why I did not go into further testing. But you can test and post the results with snaps. :smiley:


#62
  • About getVisibleSize() and getVisibleOrigin()

You can use it if you want, but getVisibleOrigin() will always be equal to (0, 0) and getVisibleSize() will always be equal to the frame size in your case (use setDesignResolutionSize(frameSize.width, frameSize.height, ResolutionPolicy::NO_BORDER) or do not use setDesignResolutionSize()).

  • About Test Case 4

In your code, you use

It is OK. But then you use

This is the cause of the wrong result. You do not need to use setContentScaleFactor() in this case.
And then boundingBox will be equal to the size of the image in this case.