要求
cocos2.4在做多个方块匹配错误时的震动效果时,调试了很久,这里记录一下
代码示例
resetBlocks(array_node){
for(let i = array_node.length-1; i >= 0; i--) {
let ts_block = array_node[i].getComponent(blcok)
let pos = array_node[i].getPosition()
//外部序号相等,且为底的方块,回到原位
//修改颜色为红色
ts_block.changeColor(true)
//播放单次音效
cc.audioEngine.setEffectsVolume(0.5);
cc.audioEngine.playEffect(this.arr_audio[1],false)
//缓动,右->左->右->左移动,且距离变大,时间变短,最后快速回到原点,形成错误时的震动效果
cc.Tween.stopAllByTarget(ts_block)
cc.tween(array_node[i])
.to(0.1,{position: new cc.Vec3(pos.x+5,pos.y,0)},{easing:"quadInOut"})
.to(0.1,{position: new cc.Vec3(pos.x-5,pos.y,0)},{easing:"quadInOut"})
.to(0.05,{position: new cc.Vec3(pos.x+8,pos.y,0)},{easing:"quadInOut"})
.to(0.05,{position: new cc.V