in function
@
bool CCMenuItemSprite::initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MenuHandler selector)
@
@
this~~>setContentSize);
@ m_pNormalImage->getContentSize() cannot get the scaled content size. It results in getting the wrong size of the menu button.
This line could be
@
this~~>setContentSize(m_pNormalImage->boundingBox().size);
@
nope. CCMenuItemSprite inherits from CCNode, has its own ContentSize, ContentSizeInPixels & boudingBox. We can’t mix up them, simply equal its contentSize to boundingBox.
Can you paste a screenshot to describe the your problem?
Actually the problem is not only in that sentence. Cocos2d-x uses CCMenuItem::rect() to calculate the menu size and the touch zone. CCMenuItem::rect() simply take the width and heighth of content size which initialled from here : this->setContentSize(m_pNormalImage->getContentSize()); This line only takes the current normal sprite’s original size (it has not been added and transformed into scene so the scale factor cannot be effective here, in my opinion).
I am not sure if the content size of the original sprite should remain the same when it scales. If so I think there should be another size to calculate rect().
In this example I uploaded, I scaled “Play” and other sprites to 50. The menu item treated the size differently so the touch zone is 200 bigger than it should be. Also there is an offset in position.
In my opinion, the content size means the original size of sprite. It wouldn’t be change in normal case.
>
If you want scale the menu item size, can do like this:
[…]
Yes, it works. Thank you. However, I want to use one set of texture image for both low and high screen resolutions. Since I work with managed sprite, the sprite manager scale it based on the current resolution when created.
If the content size remains unchanged, to scale the CCMenuItemImage should not work for its touch zone. Since rect() uses the content size only.
I found another bug. It seems there is a difference between CCMenuItemImage and CCMenuItemSprite.