Ajax WebGame,不断重新加载地图而不破坏其他页面
我正在制作一个网页游戏,它的界面非常简单,由以下部分组成:
<div>logo</div>
<div id="map"></div>
<div>some buttons here</div>
碰巧的是,id =“map”的div是我的地图出现的地方,但游戏的其他部分也看起来太像库存了。 我使用 jQuery 来做 ajax 的事情,所以它是这样的:
$(document).ready(function() {$('#map').load('map.php');});
上面的代码第一次加载 div,然后当我单击方向按钮时,它会再次调用带有一些参数的函数,以便玩家可以移动,但这是问题,我想在我使用地图时保持地图重新加载。
我尝试做一个:
setInterval("$(document).ready(function() {$('#mapadiv').load('map.php');});",1000);
事实上它确实有效,但是当我单击一个更改 div 的按钮而不是地图(如库存)时,它会快速显示库存屏幕并再次更改为地图。
当然它会改变,因为它一直在调用地图!所以我想并尝试将“setInterval”放入Map.php中,这样它只会在屏幕上时调用,但这也不起作用,它与第一次尝试的效果相同。 我想我错过了一些东西,有人可以帮助我吗? 提前致谢
Im Making a Web Game, and its interface its very simple, composed of:
<div>logo</div>
<div id="map"></div>
<div>some buttons here</div>
Happens that, the div with id = "map" is where my map appears, but also other sections of the game appears too liek the inventory.
Im using jQuery to do the ajax stuff, so its like this:
$(document).ready(function() {$('#map').load('map.php');});
The above code load the div for the first time, then when i click a directional button, it calls again that function with some parameters so the player can move, but here's the problem, i'd like to keep the map reloading while im on it.
I Tried to do an:
setInterval("$(document).ready(function() {$('#mapadiv').load('map.php');});",1000);
and in fact it did worked, but when i clicked a button that changed the div and wasnt the map (like the inventory) it rapidly shows the inventory screen and changes again to the map.
Of Course it changes, because the it keeps calling the map! so i thought and tried to put that "setInterval" inside the Map.php so it would only call while its on the screen but that didnt worked too, it did the same as the first try.
I think im missing something, can anybody help me?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您也有这个按钮:
您的脚本应该是这样的:
正如您所看到的,技巧就在
keepRefreshingMap
类中。只要地图div有它,就会不断刷新。当您打开清单时,此类将被删除,因此地图不会刷新。希望这有帮助。
I'll asume you have this buttons also:
Your script should be like this:
As you can see, the trick is in the
keepRefreshingMap
class. As long as the map div has it, it will keep refreshing. When you open the inventory, this class is removed, so the map isn't refreshed.Hope this helps.