我用sprite创建一个菜单,并为每个sprite添加一个标签。
var items = [],
for( var i=0 ; i<players.length ; i++ ) {
var frame = cc.spriteFrameCache.getSpriteFrame("listviewitem"),
spritesNormal = cc.Sprite.create(frame,cc.rect(0,0,380,100)),
spritesSelected =cc.Sprite.create(frame,cc.rect(0,0,380,100)),
spritesDisabled =cc.Sprite.create(frame,cc.rect(0,0,380,100));
var label = cc.LabelBMFont.create( players[i].name , "res/fonts/bees50.fnt" , cc.LabelAutomaticWidth, cc.TEXT_ALIGNMENT_CENTER, cc.p(0, 0) );
spritesNormal.addChild(label, 5);
var listviewSprite = new cc.MenuItemSprite(spritesNormal, spritesSelected, spritesDisabled, this.onListviewTap, { self: this, player: players[i] });
items.push(listviewSprite);
}
this._listview = new cc.Menu(items);
this.addChild(this._listview,1);
稍后我尝试通过以下方式为菜单列表的一个精灵设置动画:
var sprite = this._listview.children[i],
sprite.runAction(
cc.EaseSineIn.create(
cc.spawn(
cc.scaleTo(1,3,3),
cc.fadeOut(1)
)
)
);
但这只会淡化精灵而不是标签。缩放动画也是为标签完成的,只是褪色而不是。问题是什么?错误?
答案 0 :(得分:1)
您需要为希望递归影响的所有孩子(answer got from the forums)手动设置setCascadeOpacityEnabled(true);
。
如果你的精灵孩子有孩子(等等),你需要更多递归的东西,比如:
var setCascadeOpacityEnabledRecursively= function(node, state){
node.children.forEach(function(child){
setCascadeOpacityEnabledRecursively(child, state);
});
node.setCascadeOpacityEnabled(state);
};
然后叫它:
var sprite = this._listview.children[i];
setCascadeOpacityEnabledRecursively(sprite , true);
sprite.runAction(
cc.easeSineIn(
cc.spawn(
cc.scaleTo(1,3,3),
cc.fadeOut(1)
)
)
);