Asset Scaling, Screen Resolution, Density and Touch Gestures

  1. I saw that cocos2dx is not thinking in pixels but in an abitrary size I set.

Lets say I use 320 and 480 as the abitrary size and then set a button at the position (10,10).
If my actual screen size is 640*960 (2x as big), my button will appear at the pixel coordinate (20,20) ?

As tablets have a much different screen size, can I develop a different design for tablets?

Screen DPI matters a lot.

  1. A Label: Do I just take my normal text size (e.g. 20) and multiply it by the density (e.g. 2x) -> my new used size will be 40 or is Cocos handling this?

  2. Is there a listener for common gestures like zooming (pinching)?

  3. I have a tile map.
    Do I set a button for every touchable tile in my game and add a lambda function to handle touches
    or
    do I place a big button over everything an handle it myself (pixel to tile conversion)?

I edited my question to be more clear and less text!

  1. Yes, a position of (10, 10) with design resolution of (320, 480) will be pixel (20, 20) on a (640, 960) device. You can set the design resolution to the device resolution if you want, but it just makes things more difficult, because you would need to figure out how to deal with every different resolution yourself.

  2. Content is scaled according to the content scale factor, which is set in AppDelegate.cpp. The normal way to use this is so that content is scaled so it takes up the same amount of the screen on ever device, but you do it differently if you really want to.

  3. I do not believe cocos supports any gestures, beyond touch beginning, moving and ending.

  4. It would be more efficient to detect touch in one place and then use the coordinates to figure out which tile was touched. If each tile checks for touch individually, if you have 10,000 tiles then in the worst you could be performing 10,000 checks for 1 touch.

1 Like

Thanks for your answer!

  1. Doesnt that mean that e.g. buttons will be really large on large screens? or worse - be really small (to small for proper use) on small screens? (is that the reason why I should use a size of around 400px to work with (as phones dont get smaller?)

  2. So that indirectly states that there is no quadtree running in the background (there sure is some reason).

  1. No. It means if you have a node that is 50% of the width of the screen on one device, it will be 50% of the width of every device, at least if you are using a fixed width resolution policy. I can’t actually remember if that is the default behaviour, but if makes things a lot easier to have your app work like that.

  2. Good question. I haven’t actually used a tilemap before, so I’m not sure if it has a built-in way to handle touch. But if you need to add your own touch listeners, then cocos does not use a fancy way to determine which touch listener gets the touch.

2 Likes
  1. Isnt that the same as I said?
    -device size: 1000 * 1000, I place a button 50 * 50. (so the node is also 50 * 50?)
    -new device size 100 * 100 - node (button) will be 5 * 5 pixels (far to small)

My final thoughts:

Is there a way for me to set few resolutions to target
and
if a device is about the size of one of these resolutions:
match everything exactly to the specified resolution without scaling to the perfect screen size?

Our AppDelegate class does this, iirc

Please fix this, it just cost me 2h to figure this out. As the one user states “not very user friendly” - first hand experience here!

What captainflyaway brings up here is an interesting situation. How should one handle when setDesignResolutionSize sets a somewhat large screen size, but then the device requires scaling down where buttons and controls and scoreboards become very small? Is there a way to maintain the size of some/certain items? I realize it sounds like a longshot, just wondering.