0

抱歉标题混乱,不完全确定如何措辞。我一直在关注交互式动态 Flash Actionscript 3.0 游戏的教程,该游戏与 php 和 MySQL 通信以记住有关每个用户的某些信息。它首先向 php 文件 getsessionvars.php 发送一个请求,该请求返回可供 Flash 游戏用于检索用户信息的值。基本上这里是所有重要的代码,从动作脚本开始:

    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 数据库时尝试存储他们的坐标,然后希望在每次角色移动时更新该信息,但我想知道是否还有更多这样做的有效方法?

4

1 回答 1

0

除非您的游戏速度缓慢且基于回合制,否则您将完全走错路。同时多人游戏需要一个套接字服务器,例如 SmartFox 服务器或 ElectroTank 服务器。

电动坦克的他们编写了一本关于该主题的非常好的书:http: //www.amazon.com/ActionScript-Multiplayer-Games-Virtual-Worlds/dp/0321643364

你应该得到这本书并读一读。它涵盖了设置服务器以及如何使您的闪存实现与驱动更新的服务器良好配合。

于 2013-04-29T17:28:09.770 回答