简体   繁体   English

如何将javascript / angular.js游戏板连接到Firebase数据库

[英]How to connect javascript/angular.js game board to firebase database

I am working on an ongoing JavaScript/Angular.js game project. 我正在进行中的JavaScript / Angular.js游戏项目。

This game has a game board where the player can click their character and move it to an adjacent square by clicking on that new square. 该游戏有一个游戏板,玩家可以单击其角色,然后单击该新方块将其移动到相邻的方块。

I am now trying to add a multiplayer feature to this game by having the changes on the board data saved and transmitted to any computer looking at the firebase application that I made for the game. 我现在正尝试通过将棋盘数据上的更改保存并传输到查看我为该游戏制作的Firebase应用程序的任何计算机上,来向该游戏添加多人游戏功能。

I have tried to do something simple like the following: 我试图做一些简单的事情,如下所示:

$scope.$watch("board", updateDatabase, true);

  function updateDatabase(){
      myFirebaseRef.set($scope.board);
  }

This does update an array of arrays in the database that represents the board's square "cell" objects well. 这确实更新了数据库中一个很好地表示板的方形“单元”对象的数组。 However, it breaks some other functionality in the code like an AI pathfinding check for a wall using an isWall attribute. 但是,它破坏了代码中的其他功能,例如使用isWall属性对墙进行AI寻路检查。 (I am not sure why this is.) (我不确定为什么会这样。)

What would you recommend to fix the issue and be able to grab the data back so that other computers can see the change to the firebase app automatically? 您将提出什么建议来解决此问题并能够获取数据,以便其他计算机可以自动查看对Firebase应用程序的更改?

I put the files on plunker here: http://plnkr.co/edit/80UEpIoXtriDMLfdsgN9?p=streamer&s=Hga74ZPLuT0rZ0h3 (The main file is script.js) 我将文件放在此处的plunker上: http ://plnkr.co/edit/80UEpIoXtriDMLfdsgN9?p=streamer&s=Hga74ZPLuT0rZ0h3(主文件是script.js)

Thank you for your time and have a great day! 谢谢您的时间,祝您度过愉快的一天!

-Matt S. -马特·S。

You should use "Angularfire" is a library that lets you handle information between AngularJS and Firebase in a easier way. 您应该使用“ Angularfire”这个库,通过它可以更轻松地处理AngularJS和Firebase之间的信息。

Go to their quick start page and you will get a grasp of it in 5 ~ 10 minutes. 转到他们的快速入门页面,您将在5到10分钟内掌握它。 Is pretty awesome! 太棒了!

This is the link: https://www.firebase.com/docs/web/libraries/angular/quickstart.html 这是链接: https : //www.firebase.com/docs/web/libraries/angular/quickstart.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM