Position elements in percentage or pixels?


When positioning my sprites (not UI), such as player, world top, floor, etc… should I be positioning with percentage or pixels?

worldCeiling->setPosition(origin.x, visibleSize.height - (visibleSize.height * 0.1) + origin.y);


worldCeiling->setPosition(origin.x, visibleSize.height - 128 + origin.y);

My confusion about this is because I’ve got multi-resolution support as such a big focus when using cocos2d, maybe even too much. I’m still getting my head around how multi-resolution support should be handled in a game.

I’m using C++ and designing for IOS.


Entirely your call. I do both in every game I make depending upon what I need.


Personally I always position in pixels, but pre-calculate percentages where that is relevant, so I will use a variable which is calculated using (e.g. float topBarheight = visibleSize.height * 0.1) and use that to set or check positions.


If I use pixels and never percentage, can I still make my game look good on multiple devices with the same code? Or is that when I need to use percentage positioning?


I prefer calculations with percentage. It’s kind of more readable for me.


You would need to adjust your math so each device used some soft of scale factor. and then multiply your position code by that scale factor. This is a common take. Something most developers do all the time.