代码如下, 资源图片就1张120x120的,建立了16个节点对象。
NumberUtils.random就一个随机函数,用不用结果一样。
cc.Class({
extends: cc.Component,
properties:{
nItem: {
default: [],
type: [cc.Node],
}
},
onLoad(){},
onEnable(){},
setData( _d0, _d1 ){
let r = cc.view.getDesignResolutionSize();
let pos = this.node.convertToNodeSpaceAR( _d0 );
pos.x += r.width / 2;
pos.y += r.height / 2;
let lr = true;
for( let i = 0 ; i < this.nItem.length; i ++ ){
let node = this.nItem[i];
this._init_tween( node, pos, lr );
lr = !lr;
}
},
setView(){},
start(){
this._index = 0;
for( let i = 0 ; i < this.nItem.length; i ++ ){
this.nItem[i].active = true;
this.nItem[i].runAction( this.nItem[i]._action );
}
},
onDisable(){
this.node.destroy();
},
onDestroy(){},
_init_tween( _node, _pos, _lr ){
let ox = NumberUtils.random( 0, 150 ) * ( _lr ? -1 : 1 );
let oxf1 = NumberUtils.randomFloat( 1.5, 2 );
let oxf2 = NumberUtils.randomFloat( 2, 3 );
let oxf3 = NumberUtils.randomFloat( 2, 4 );
let pos1 = cc.v2( _pos.x + ( ox / oxf1 ), _pos.y + NumberUtils.random( 0, 400 ) );
let pos2 = cc.v2( pos1.x + ( ox / oxf2 ), pos1.y + NumberUtils.random( 0, 250 ) );
let pos3 = cc.v2( pos2.x + ( ox / oxf3 ), _pos.y + NumberUtils.random( -100, -250 ) );
let rt = _lr ? NumberUtils.random( -60, -180 ) : NumberUtils.random( 60, 180 );
let st = NumberUtils.randomFloat( 0.5, 1 );
let sp = NumberUtils.randomFloat( 0.5, 0.8 );
_node.position = _pos;
_node._action = cc.sequence(
cc.spawn(
cc.bezierTo( sp, [ pos1, pos2, pos3 ] ),
cc.rotateTo( sp, rt ),
cc.scaleTo( sp, st ),
),
cc.callFunc( ()=>{
_node.active = false;
this._index ++;
if( this._index >= this.nItem.length ){
this.node.active = false;
}
} ) );
},
});
自己顶下自己。和写法无关,因为同屏会有richtext的原因。隐藏richtext就不卡了。