2013-04-29 67 views
0

对不起,令人困惑的标题,并不完全知道如何说话。我一直在关注一个交互式动态Flash ActionScript 3.0游戏的教程,该游戏与php和MySQL进行通信以记住每个用户的某些信息。它首先向PHP文件getsessionvars.php发送一个请求,该请求返回闪存游戏可以用来取消用户信息的值。基本上这里是所有重要的代码,从动作开始:在舞台上有多个玩家动作3.0 php MySQL

stop(); 
    // Assign a variable name for our URLVariables object 
    var variables:URLVariables = new URLVariables(); 
    // Build the varSend variable 
    // Be sure you place the proper location reference to your PHP config file here 
    var varSend:URLRequest = new URLRequest("getsessionvars.php"); 
    varSend.method = URLRequestMethod.POST; 
    varSend.data = variables; 
    // Build the varLoader variable 
    var varLoader:URLLoader = new URLLoader; 
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES; 
    varLoader.addEventListener(Event.COMPLETE, completeHandler); 
    variables.myRequest = "bringit"; 
    // Send the data to the php file 
    varLoader.load(varSend); 
    // When the data comes back from PHP we access it here  
    function completeHandler(event:Event):void{ 

     var idVar = event.target.data.id_var; 
     var userNameVar = event.target.data.uname_var; 
     var passVar = event.target.data.upass_var; 
     var resultStatus = event.target.data.my_result; 
     var coordX=event.target.data.coordx; 
     var coordY=event.target.data.coordy; 
     if (resultStatus == "no_session"){ 
      gotoAndStop("no_session"); 
     } else if (resultStatus == "no_exist"){ 
      gotoAndStop("no_exist"); 
     } else if (resultStatus == "all_good"){ 
      userid_txt.text = idVar; 
      username_txt.text = userNameVar; 
      password_txt.text = passVar; 
      gotoAndStop(5); 
      var other:otherPeople = new otherPeople(); 
      addChild(other); 
      other.x=coordX; 
      other.y=coordY; 
     } 
    } 

然后getsessionvars.php:

<?php 
    session_start(); 
    include_once("php_includes/check_login_status.php"); 
    $id = ""; // Initialize $id var 
    $username = ""; // Initialize $username var 
    $password = ""; // Initialize $password var 
    if (isset($_POST['myRequest']) && $_POST['myRequest'] == "bringit"){ 

     $id = preg_replace('#[^0-9]#i', '', $log_id); 
     $username = preg_replace('#[^a-z0-9]#i', '', $log_username); 
     $password = preg_replace('#[^a-z0-9]#i', '', $log_password); 

     // Check database to see if the id is related to this password 
     include_once("connect.php"); 
     mysql_query("INSERT INTO online ('id','player','xpos','ypos') VALUES('','{$username}','10','30')"); 
     $sql = mysql_query("SELECT * FROM users WHERE id='$id' AND username='$username' LIMIT 1"); 
     $numrows = mysql_num_rows($sql); 
     $sqla=mysql_query("SELECT * FROM online"); 
      echo "my_result=all_good&id_var=$id&uname_var=$username&upass_var=$password&coordx=30&coordy=50"; 
    }// close inital if condition 
    ?> 

我的问题是:我怎样才能让这个多个用户可以出现在屏幕在同一时间?正如你可以注意到的,我已经试图存储玩家首次登录MySQL数据库时的坐标,然后希望每次角色移动时都更新这些信息,但我想知道是否还有更多这样做的有效方法?

回答

0

除非您的游戏速度缓慢并基于回合,否则您将完全走错了路线。 同步多人游戏需要的是套接字服务器,如SmartFox服务器或ElectroTank服务器。

他们在球员电箱放在一起非常非常好的一本书的题目是 http://www.amazon.com/ActionScript-Multiplayer-Games-Virtual-Worlds/dp/0321643364

你应该得到这本书,不妨一读。它包括设置服务器以及如何使您的Flash实施与驱动更新的服务器协同工作。