Hi!
It is very easy to support both ipad retina and the normal ipad because have the same aspect…So you simply just set the contentScaleFactor to 2 if you create images that is all based on ipad Retina…
BUT what can I do to when it comes to something like iPhone 6 which has another aspect and needs to be scaled differently in the x and y axis…Because the contentScaleFactor scales both of the directions with the same value right?
Thanks, hope you get me!
Maybe @slackmoehrle you know who can help
Cheers
One thing that I do, is I set my own scale factor for each device. I literally make this up depending upon my art. All of my math is then multiplied by the scale factor. It works well. I can make any adjustments I need. It was a bit more work on my end to make these decisions, but the result is perfect on each device I test on.
Yea i can see that when it comes to an aspect that needs the same scale for both x and y axis. But what if my original art is based on iPad retina and i should make support iPhone 6 which has another aspect, that needs a different value in the x and y axis. Therefore i can’t just multiply by the scale factor, because they should be two different values…
Right? Otherwise, how…
Thanks!
We have done lots to scale all parts of our first game using Cocos2d-x but stumped on one item. We have used Bitmaplabels with our own textured fonts. Here the buttons and other on-screen images re-scale as we change screen size but the Bitmaplabels always remain the same size. We cannot figure out how to resize the Biymaplabels along with everything else on the screen. All tips and help appreciated.
1 Like
Yea, a method for that would be nice to know… 
@slackmoehrle do you know how to?
Bitmap fonts are not scalable. You have to use TTF for that.
http://cocos2d-x.org/programmersguide/6/index.html#label
nono, i am talking about the scaling stuff for all the different images we are adding along the game and how we need to scale them in different axis with different values for x and y. All being measured from the current screen size and the screen size the image was originally created for?
Thanks! This is something that i know a lot want to know…
Share the reliable code you use for multi screen support 
well, it works for me, but for others, you might not agree.
I have a singleton class that when the game starts, I set a bunch of things I need. I make decisions to screen width, height, scale factor and other things. I have an const std::pair<std::pair<int, int>, float>& screenDetails that I use when I need to make decisions.
I would be great if you share with us just the piece of code related to multiscreen handling.
oh, maybe I mis-understood, this isn’t multiscreen like you want, it is how I deal with multi-resolution.
No my bad. Multi resolution is exactly what i’m talking about 
I don’t know that this will help:
#ifndef _SMGameObject_H_
#define _SMGameObject_H_
#include "SMPlatformDefines.h"
#include <iostream>
#ifdef USING_COCOS2DX
#include "cocos2d.h"
#endif
typedef struct tagResource
{
std::pair<int, int> size;
char directory[15];
} Resource;
static Resource AppleSDPhoneResource = {std::make_pair(960, 640), "iphonesd"};
static Resource AppleHDPhoneResource = {std::make_pair(1136, 640), "iphonehd"};
static Resource AppleSDTabletResource = {std::make_pair(1024, 768), "ipadsd"};
static Resource AppleHDTabletResource = {std::make_pair(2048, 1536), "ipadhd"};
static Resource AppleHDiPhone6Resource = {std::make_pair(1334, 750), "iphone6"};
static Resource AppleHDiPhone6PResource = {std::make_pair(2208, 1242), "iphone6p"};
SMENGINE_NAMESPACE_BEGIN
class SMGameObject
{
public:
SMGameObject() {};
SMGameObject(const SMGameObject&);
SMGameObject& operator= (const SMGameObject&);
// Constructor
template <class T = SMGameObject>
static T* Instance()
{
static T* _instance = nullptr;
if (_instance == nullptr)
{
_instance = new T;
// small delay to keep launch image up longer
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
return _instance;
}
// things that must happen upon creation
inline void initInstance()
{
display();
resources();
};
inline void display()
{
#ifdef USING_COCOS2DX
auto director = cocos2d::Director::getInstance();
setScreenWidth(cocos2d::Size(director->getOpenGLView()->getFrameSize()).width);
setScreenHeight(cocos2d::Size(director->getOpenGLView()->getFrameSize()).height);
setScaleFactor();
if (getDebug())
{
log("screen width: ", getScreenWidth(), "screen height: ",getScreenHeight());
log("scale factor: ", getScaleFactor());
}
#endif
};
inline void resources()
{
#ifdef USING_COCOS2DX
_searchPaths.push_back("res");
_fileUtils = cocos2d::FileUtils::getInstance();
_fileUtils->setSearchPaths(_searchPaths);
_spritecache = cocos2d::SpriteFrameCache::getInstance();
_spritecache->addSpriteFramesWithFile("sprites.plist");
#endif
};
// getters and setters
inline const bool& getDebug() { return _bDebug; };
inline void setDebug(bool b) { _bDebug = b; };
// screen functions
inline const int& getScreenWidth() { return _screenWidth; };
inline void setScreenWidth(int i)
{
_screenWidth = i;
assert(_screenWidth > 0);
};
inline const int& getScreenHeight() { return _screenHeight; };
inline void setScreenHeight(int i)
{
_screenHeight = i;
assert(_screenHeight > 0);
};
inline const std::pair<int, int> getScreenSize()
{
return std::make_pair(getScreenWidth(), getScreenHeight());
};
inline bool& isRetina() { return _bIsRetina; };
inline bool& getIsRetina() { return _bIsRetina; };
inline void setIsRetina(bool b) { _bIsRetina = b; };
inline bool& isIPhone() { return _bIsIPhone ; };
inline bool& getIsIPhone() { return _bIsIPhone; };
inline void setIsIPhone(bool b) { _bIsIPhone = b; };
inline bool& isIPad() { return _bIsIPad; };
inline bool& getIsIPad() { return _bIsIPad; };
inline void setIsIPad(bool b) { _bIsIPad = b; };
inline bool& isIPhone6() { return _bIsIPhone6 ; };
inline bool& getIsIPhone6() { return _bIsIPhone6; };
inline void setIsIPhone6(bool b) { _bIsIPhone6 = b; };
inline bool& isIPhone6P() { return _bIsIPhone6P ; };
inline bool& getIsIPhone6P() { return _bIsIPhone6P; };
inline void setIsIPhone6P(bool b) { _bIsIPhone6P = b; };
inline const float& getScaleFactor()
{
return _scaleFactor;
};
inline void setScaleFactor()
{
if (getScreenWidth() == AppleHDTabletResource.size.first)
{
// ipad 3 and 4, ipad mini 2 (retina)
_searchPaths.push_back(AppleHDTabletResource.directory);
setIsRetina(true);
setIsIPad(true);
setIsIPhone(false);
setIsIPhone6(false);
setIsIPhone6P(false);
}
else if (getScreenWidth() == AppleSDTabletResource.size.first)
{
// ipad 1 and 2, ipad mini 1 (non-retina)
_searchPaths.push_back(AppleSDTabletResource.directory);
setIsIPad(true);
setIsRetina(false);
setIsIPhone(false);
setIsIPhone6(false);
setIsIPhone6P(false);
}
else if (getScreenWidth() <= AppleHDPhoneResource.size.first)
{
// iphone 5, 5s, ipod (retina)
_searchPaths.push_back(AppleHDPhoneResource.directory);
setIsIPad(false);
setIsRetina(true);
setIsIPhone(true);
setIsIPhone6(false);
setIsIPhone6P(false);
}
else if (getScreenWidth() <= AppleHDiPhone6Resource.size.first)
{
// iphone 6
_searchPaths.push_back(AppleHDiPhone6Resource.directory);
setIsIPad(false);
setIsRetina(true);
setIsIPhone(true);
setIsIPhone6(true);
setIsIPhone6P(false);
}
else if (getScreenWidth() <= AppleHDiPhone6PResource.size.first)
{
// iphone 6+
_searchPaths.push_back(AppleHDiPhone6PResource.directory);
setIsIPad(false);
setIsRetina(true);
setIsIPhone(true);
setIsIPhone6(false);
setIsIPhone6P(true);
}
else
{
// something else, so super small
_searchPaths.push_back(AppleSDPhoneResource.directory);
setIsIPad(false);
setIsRetina(false);
setIsIPhone(true);
setIsIPhone6(false);
setIsIPhone6P(false);
}
if (isRetina() && isIPad())
{
_scaleFactor = 2;
}
else if (isRetina() && isIPhone())
{
if (isIPhone6P())
{
_scaleFactor = 2.25;
}
else if (isIPhone6())
{
_scaleFactor = 1.35;
}
else
{
_scaleFactor = 1.15;
}
}
else
{
_scaleFactor = 1;
}
assert(_scaleFactor > 0.0);
};
// functions
template <typename T>
static void log(T t)
{
//std::cout << __PRETTY_FUNCTION__ << std::endl;
std::cout << t << std::endl;
}
template<typename T, typename... Args>
static void log(T t, Args... args) // recursive variadic function
{
//std::cout << __PRETTY_FUNCTION__ << std::endl;
std::cout << t << std::endl;
log(args...) ;
}
private:
bool _bDebug = true;
int _screenWidth = 0;
int _screenHeight = 0;
float _scaleFactor = 0.0;
std::vector<std::string> _searchPaths;
bool _bIsRetina = false;
bool _bIsIPhone = false;
bool _bIsIPad = false;
bool _bIsIPhone6 = false;
bool _bIsIPhone6P = false;
#ifdef USING_COCOS2DX
cocos2d::FileUtils* _fileUtils;
cocos2d::SpriteFrameCache* _spritecache;
#endif
};
SMENGINE_NAMESPACE_END
#endif // _SMGameObject_H_
Edit:
And I call in AppDelegate, like:
SMEngine::SMGameObject::Instance<GameObject>();
SMEngine::SMGameObject::Instance<GameObject>()->initInstance();
SMEngine::SMGameObject::Instance<GameObject>()->createMainScene();
director->runWithScene(SMEngine::SMGameObject::Instance<GameObject>()->getMainScene());
1 Like
Sure it will. Thank you very much.
I do not really get it. First, “SMPlatformDefines.h” not found?
And how will that make the nodes and the scene scale the the fitting size?
Thanks!
because this is my code.
It doesn’t directly. This is just how I keep track of scale factor, and other properties so that when I need to size Node etc, I do it with these numbers handy.
1 Like