Cocos2d-x 3.13 crashes when not using design resolution

Hello, after updating to cocos 3.13 my app crashes because of something to do with design resolutions and content scale factors. I have never used those features nor am I intending to use them. Have they became mandatory since 3.13?

The crash is caused by removing this code block:

Thank you.

Hello crugthew, If you are not using design resolution, what concept are used , plz tell me and send me your code (and what assests are you used)

@TarunRNF

Hi, the concept is very simple. Take the shorter side of the screen (if portrait mode, then take the width) and scale everything accordingly.

So as an example lets take the logo sprite:

Position: Point(getContentSize().width * 0.725f, getContentSize().height * 0.75f);
Scale: getContentSize().height * 0.175f / logo->getContentSize().height;

And thats it. On all screens it will always take the same amount of “space” and will always be in the same relative position.

As for resources, I select the appropriate ones like this, where “high” is something like an iPad resolution and “medium” is 50% of “high”, and “low” is 50% of “medium”. So the scale of the sprites is always between 0.8f-ish and 1.2f-ish, which does not cause any distortion or some other bad stuff. :smiley:

1 Like

Hi,

I never use design resolution either. I find some other options better and more flexible.

@crugthew Yes, App does crashes if there is no design resolution given.

Thanks

We do something similar to position and size objects, we just set the design resolution = screen size in pixels.

Hi guys!

I do not understand why you want to calculate the position and the scale manually.
Design Resolution is here to allow you to set the position in absolute or relative coordinates. And you do not need to scale the position coordinates.

Hi,

Because by using relative position (getContentSize().width or heigh * some_percentage) i know exactly where my objects will be no matter the orientation, size or anything. On the other hand design resolution constrains me to some fixed aspect ratio, size…

Anyway, I’m not saying that my approach is better or that design resolution should be removed or something similar. I was simply surprised that it became mandatory.

This is my current work-around if anyone needs this:

Director::getInstance()->getOpenGLView()->setContentScaleFactor(1.0f);
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(Director::getInstance()->getOpenGLView()->getFrameSize().width, Director::getInstance()->getOpenGLView()->getFrameSize().height, ResolutionPolicy::EXACT_FIT);
1 Like

You can use getVisibleSize() for relative positioning.

I am also not saying that the standard approach is better, it just simplifies the positioning and the scaling.

Just one more point.

It is FAR easier to work with floats that range from 0.0f to 1.0f than, say, having some size that you made up (like 800x480) and working with that.

I would much rather see my position as {0.25f, 0.1f} than {200, 48}, because no matter the screen I’m running at I always know approx. where my object will be.

And {200, 48} just doesn’t make sense if i would be be porting some game i made for 800x480 phone to Apple TV (<- just an example!!!).

OK. I understood you. Apparently it’s a matter of preference which to use.
getVisivleSize() is a good choice for me because I prefer to work in the 480x800 coordinates. But it is not so attractive for you.

In any case, you have already found the work-around. :smile:

Fix is here: https://github.com/cocos2d/cocos2d-x/pull/16533

1 Like

@ricardo Thank you. :slight_smile: