runAction 函数也会缩放精灵 children,但不会使它们褪色
runAction function will scale also children of a sprite, but not fade them
我用 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);
稍后我尝试通过以下方式为菜单列表中的一个 sprite 设置动画:
var sprite = this._listview.children[i],
sprite.runAction(
cc.EaseSineIn.create(
cc.spawn(
cc.scaleTo(1,3,3),
cc.fadeOut(1)
)
)
);
但这只会淡出精灵而不是标签。缩放动画也为标签完成,只是褪色没有。问题是什么?错误?
您需要在您希望递归影响的所有 children 上手动设置 setCascadeOpacityEnabled(true);
(answer got from the forums)。
如果你的精灵 children 有孩子(等等),你需要一些更递归的东西,比如:
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)
)
)
);
我用 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);
稍后我尝试通过以下方式为菜单列表中的一个 sprite 设置动画:
var sprite = this._listview.children[i],
sprite.runAction(
cc.EaseSineIn.create(
cc.spawn(
cc.scaleTo(1,3,3),
cc.fadeOut(1)
)
)
);
但这只会淡出精灵而不是标签。缩放动画也为标签完成,只是褪色没有。问题是什么?错误?
您需要在您希望递归影响的所有 children 上手动设置 setCascadeOpacityEnabled(true);
(answer got from the forums)。
如果你的精灵 children 有孩子(等等),你需要一些更递归的东西,比如:
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)
)
)
);