物体碰撞时,设置屏幕抖动
具体内容
// 抖动方法
shakeF(node){
let x = node.x; let y = node.y;
let offset = 10;
let action = cc.repeatForever(
cc.sequence(
cc.moveTo(0.018, cc.v2(x + (5 + offset), y + (offset + 7))),
cc.moveTo(0.018, cc.v2(x - (6 + offset), y + (offset + 7))),
cc.moveTo(0.018, cc.v2(x - (13 + offset), y + (offset + 3))),
cc.moveTo(0.018, cc.v2(x + (3 + offset), y - (6 + offset))),
cc.moveTo(0.018, cc.v2(x - (5 + offset), y + (offset + 5))),
cc.moveTo(0.018, cc.v2(x + (2 + offset), y - (8 + offset))),
cc.moveTo(0.018, cc.v2(x - (8 + offset), y - (10 + offset))),
cc.moveTo(0.018, cc.v2(x + (3 + offset), y + (offset + 10))),
cc.moveTo(0.018, cc.v2(x + (0 + offset), y + (offset + 0)))
)
)
node.runAction(action);
this.scheduleOnce(function() {
node.stopAction(action);
node.x = x; node.y = y;
}, 0.3);
},
把要抖动的组件节点传入方法中
如下
// 获取要抖动的节点
let nodeData=this.node (or getComponent("xxx").node)
// 调用方法并传入节点
this.shakeF(nodeData)