import Common from "../common/Common"; // Learn TypeScript: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class SceneObjectManager extends cc.Component { @property(cc.Node) nodeShip: cc.Node = null; @property(cc.Node) nodeCloud1: cc.Node = null; @property(cc.Node) nodeCloud2: cc.Node = null; @property(cc.Node) nodeCloud3: cc.Node = null; start () { this.legtRightMove(this.nodeShip,-250,-113,30,50) this.legtRightMove(this.nodeCloud1,-400,-268,30,50) this.legtRightMove(this.nodeCloud2,-320,-250,20,60) this.legtRightMove(this.nodeCloud3,-350,-250,10,70) } legtRightMove(moveNode:cc.Node,minSx:number,maxSx:number,minTime:number,maxTime:number){ let startX:number = Common.getRandom(minSx,maxSx) moveNode.position = new cc.Vec2(startX,moveNode.position.y); let action = cc.moveTo(Common.getRandom(minTime,maxTime),new cc.Vec2(Common.getRandom(700,900),moveNode.position.y)) moveNode.runAction(cc.repeatForever(cc.sequence(action,cc.callFunc(function(){ moveNode.position = new cc.Vec2(startX,moveNode.position.y); }.bind(this))))); } }