网络游戏,或东西的速度,然后将Ajax用于发送/接收数据 [英] Online gaming, or something faster then ajax for sending/receiving data

查看:240
本文介绍了网络游戏,或东西的速度,然后将Ajax用于发送/接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做这个短,我可以。

I'm making this as short as I can.

我到目前为止已经完成: 本场比赛我都将通过JavaScript使用的setTimeout 的setInterval 运行。它不是Flash或任何特殊。我到目前为止做出像一个试运行(这样你就可以更好地理解),是pretty的多环阿贾克斯继续将请求发送到PHP页面尽可能快地就可以了,然后PHP读取 $ _从请求的URL GET ,那么PHP编辑一个名为p1.html与 $ _ GET ,这简直是玩家1的文件x和y轴坐标。因此,在播放器2的浏览器,它pretty的多少做了什么,我上面说的,现在当它接收到Ajax请求,它会收到玩家的坐标1。所以JavaScript并做什么的,和移动播放器1播放器2的浏览器。这就是我已经作出自己,我测试了它,是的,它的工作原理,并是的,它是永恒的,当我修复了所有的错误和东西。

What I've done so far: The game I have will be running with JavaScript using setTimeout or setInterval. It's not flash or anything special. What I have made so far as like a test run (so you can understand better), is pretty much loop Ajax to keep sending requests to a PHP page as fast as it can, which then PHP reads the $_GET in the url from the request, then PHP edits a file called p1.html with the $_GET, which is simply player 1's x and y-axis coordinates. So in player 2's browser, it pretty much did what I said above, and now when it receives the Ajax request, it will receive the coordinates of player 1. So JavaScript does what it does, and moves player 1 on player 2's browser. That's what I already made myself, and I tested it and yes it works and yes it lasts forever when I fixed all the bugs and stuff.

话说,这是我到目前为止已经取得了,但是这是不够快,如果我想就像一个在线格斗游戏或实时侧滚动游戏。所以,这就是我需要帮助。我知道在w3schools.com了很多东西,但我只是不知道如何得到这个工作做好。这可能是它。我只需要浏览器1,获取数据到浏览器2,这样的事情1100200或稍长时间实际,并具有浏览器2读取的数据作为变量在JavaScript(如 X =收到什么数据; ),这只是它。 JavaScript的将做休息。

Saying that, that's what I've made so far, but this isn't fast enough if I wanted like a online fighting game or a real time side scrolling game. So that's what I need help with. I know a lot of stuff on w3schools.com, but I just don't know how to get this job done. That's probably it. I just need browser 1, to get data to browser 2, something like this "1,100,200" or a little longer actually, and have browser 2 read that data as a variable in JavaScript (anything like x="received data";), and that's just it. JavaScript will do the rest.

我敢肯定,我可以计划我需要的一切我自己,但是从A点发送数据到B点像50次,第二次,我不知道这件事。甚至没有一个名字。而在去年,URL和例子将是非常好的(更清晰)。特别是,如果它已经在w3schools.com(举例),我只是错过了。

I'm sure I can program everything I need myself, but for sending data from point A to point B like 50 times a second, I just don't know anything about it. Not even a name. And last, urls and examples would be very nice (to be clearer). Especially if it's already on w3schools.com (with examples) and I just missed it.

推荐答案

答案很简单:使用的WebSockets 。他们允许的数据在两个方向上为表面上的瞬时相互作用的直接推。它们消除从哪个是缓慢和重(包括为服务器)客户端提取数据的需要。需要注意的是在我最喜欢的游戏通知推送。

The answer is simple : Use websockets. They allow the immediate push of data in both directions for seemingly instantaneous interactions. They eliminate the need of pulling data from the client which is slow and heavy (including for the server). Note that's the solution used in my favorite game for notification push.

您可以通过本次的介绍上的WebSockets在PHP 。但是请注意,PHP确实是不长的连接处理和实时游戏中最有效的解决方案(可能preFER围棋,Node.js的,JAVA等)。

You might be interested by this introduction on websockets on PHP. But note that PHP really isn't the most efficient solution for long connections handling and real time games (you might prefer Go, node.js, java, etc.).

这篇关于网络游戏,或东西的速度,然后将Ajax用于发送/接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆