var animationType = cc.Enum({ UpAndDown: -1, //手指滑动 FingerSliding: -1, }); cc.Class({ extends: cc.Component, properties: { //类型 animationEnum: { default: animationType.UpAndDown, type: cc.Enum(animationType), }, }, random(max, min) { return Math.floor(Math.random() * (max - min + 1) + min); }, start() { //初始化任务 switch (this.animationEnum) { case animationType.UpAndDown: this.node.stopAllActions(); var s = cc.sequence(cc.moveBy(0.5, 0, 20), cc.moveBy(0.5, 0, -20)); var repeat = cc.repeatForever(s); this.node.runAction(repeat); break; case animationType.FingerSliding: this.node.stopAllActions(); var s = cc.sequence(cc.moveBy(0, -200, 130),cc.moveBy(1, 200, -130),cc.delayTime(1)); var repeat = cc.repeatForever(s); this.node.runAction(repeat); break; } }, });