Hi,
New to cocos2dx, find it very confusing to understand what does all size work in the framework.
I found when doing a scale thing in the appdelagate, the result of sprite->getContentSize()
as well as sprite->getBoundingBox().size
will change due to change of glview
.
Since I want to the designed resolution to be 1920x1080
targeted to the main mobile devices, but I want my working PC resolution to be smaller so that the game window won’t take “too much” of the screen while I am working.
So I made change to the AppDelegate.cpp
as following
static cocos2d::Size designResolutionSize = cocos2d::Size(1920, 1080);
static cocos2d::Size workingResolutionSize = cocos2d::Size(1920 * 0.5, 1080 * 0.5);
...
bool AppDelegate::applicationDidFinishLaunching() {
...
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("test", cocos2d::Rect(0, 0, workingResolutionSize.width, workingResolutionSize.height));
#else
glview = GLViewImpl::create("test");
#endif
...
}
As you can see I defined a resolution as half the size of 1080p and when I working with the game the window size satisfy me well.
But then I found the contentSize
or boundingBox
size will not keep the same as the raw image
To test that, I made a rectangle block 100x100
pixels, and loaded it and tested it as flowing (not sure whether it’s plist that to blame, so I made test both with plist and with raw image)
this->cache = SpriteFrameCache::getInstance();
this->cache->addSpriteFramesWithFile("plist/texture.plist");
auto test100 = Sprite::createWithSpriteFrameName("test100.png");
auto test100raw = Sprite::create("image/test100.png");
test100->setAnchorPoint(Vec2(0, 0));
CCLOG("visualbe size is (%f, %f)", Director::getInstance()->getVisibleSize().width, Director::getInstance()->getVisibleSize().height);
CCLOG("test100 size bound (%f,%f)", test100->getBoundingBox().size.width, test100->getBoundingBox().size.height);
CCLOG("test100 content size (%f,%f)", test100->getContentSize().width, test100->getContentSize().height);
CCLOG("test100raw size bound (%f,%f)", test100raw->getBoundingBox().size.width, test100raw->getBoundingBox().size.height);
CCLOG("test100raw content size (%f,%f)", test100raw->getContentSize().width, test100raw->getContentSize().height);
And the output of the log is as following:
visualbe size is (1920.000000, 1080.000000)
test100 size bound (187.499985,187.499985)
test100 content size (187.499985,187.499985)
test100raw size bound (187.499985,187.499985)
test100raw content size (187.499985,187.499985)
To make things clear, I will upload the property inspector screenshot of the raw image(same one in plist as well as raw image) here:
And I really don’t know why this happens, and totally confused.
Could some one explain why the content size is almost 2 times scaled and more over why it’s not an even 200x200
instead of 187.???x187.???
?