[英]scaling a CCMenuItem in Cocos2d (Objective-C)
我正在嘗試制作具有縮放圖像的CCMenuItem。 例如,我嘗試過:
CCSprite* normalSprite = [CCSprite spriteWithFile:@"button_play.png"];
CCSprite* selectedSprite = [CCSprite spriteWithFile:@"button_play.png"];
selectedSprite.scale = 1.2;
CCMenuItem menuItem = [CCMenuItemSprite
itemFromNormalSprite:normalSprite
selectedSprite:selectedSprite
target:self
selector:@selector(onPlay:)];
但看起來CCMenuItemSprite忽略了底層精靈的規模。 有沒有辦法做到這一點(除了創建底層圖像的縮放版本)? 謝謝。
關於CCMenuItem如何工作,Thyrgle是正確的。
但是,肯定有辦法做你想做的事。 您需要做的就是子類化CCMenuItem並覆蓋選定和未選擇的方法以實現您想要的效果。 事實上,我很確定你可以從CCMenuItemLabel剪切和粘貼代碼,因為將項目縮放到1.2正是它的作用。 (事實上,它做得更好,因為它可以改變規模變化。)
-(void) selected
{
// subclass to change the default action
if(isEnabled_) {
[super selected];
[self stopActionByTag:kZoomActionTag];
CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:1.2f];
zoomAction.tag = kZoomActionTag;
[self runAction:zoomAction];
}
}
-(void) unselected
{
// subclass to change the default action
if(isEnabled_) {
[super unselected];
[self stopActionByTag:kZoomActionTag];
CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:1.0f];
zoomAction.tag = kZoomActionTag;
[self runAction:zoomAction];
}
}
CCMenuItemImage類也可用於在CCMenu中顯示具有其比例的圖像。請檢查此鏈接http://www.cocos2d-iphone.org/forum/topic/8310
[mainMenu alignItemsVerticallyWithPadding:15.0f];
不,沒有別的辦法。 問題是menuItem
只承認sprite的文件部分。 它不是在尋找其他屬性,例如scale
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.