Here's Client 2 Moving Role after Client 1 Presses the Rocker
p2 does not move until p1 moves the rocker
Set judgment move var zou=false
zou=true when touching the rocker;
Pass zou to server and zou to p2
function chuans(){ var cmd = { "ziji":"1", "x":"woshi1", "to":"2", "x6":ang.jieguo, "zou":zou, // "y":sky.y, }; let Msg:string = JSON.stringify(cmd); // var cmd6 = 64; console.log("Connect successfully, send data:" + Msg); this.webSocket.writeUTF(Msg); }
Store the value returned by the server in the class
function onReceiveMessage(e: egret.Event): void { var msg = this.webSocket.readUTF(); var cx=eval('('+msg+')'); dxx.run(cx.fff,cx.y,cx.zou); console.log("Data received:" + cx.fff+ang.jieguo+"......................................."); }
Class dx
class dx{ public chuanx=null; public chuany=null; public x=null; public y=null; public chuanzou=null; public zouu=null; // public shpwaix=null; // public neiy=null; // public shpwaiy=null; public run(chuanx,chuany,chuanzou){ this.x=chuanx; this.y=chuany; this.zouu=chuanzou; } }
In timmer, which controls p1 client to display p2 role movement, it is judged that if the returned zou is true to prove that another client is touching the rocker, then the position of role sky6 is updated in this client.
function cont6246(){ if(dxx.zouu==true){//If the zou returned from the other client is true, the other client touches the rocker and returns true. sky6.x=Math.cos(dxx.x)*10+sky6.x; console.log(group.x+"xxxxxxxxxxxxxxxxxxxxxxxxxxx"+group.y); sky6.y=Math.sin(dxx.x)*10+sky6.y;//Math.cos(ang.jieguo)*10 // var request = new egret.HttpRequest(); // var zou="?x="+sky.x+"&y="+sky.y+""; //request.responseType = egret.HttpResponseType.TEXT; //request.open("http://127.0.0.1:3030/66/servlet/hf"+zou,egret.HttpMethod.GET); //request.send(); //request.addEventListener(egret.Event.COMPLETE,this.onGetComplete,this); //request.addEventListener(egret.IOErrorEvent.IO_ERROR,this.onGetIOError,this); //request.addEventListener(egret.ProgressEvent.PROGRESS,this.onGetProgress,this); if(tingbeijing==true){//If false means that the map will not move beyond the boundary group.x=group.x-Math.cos(dxx.x)*2; //Longitudinal rolling position group.y =group.y-Math.sin(dxx.x)*2//group is the map container sprite } } }