cocos中常用的一些第三方庫(proto、jszip、astar等)
阿新 • • 發佈:2022-05-06
在論壇看到帖子你想在cocos中使用哪些npm包,點進去看到支援一些常用的包。但是這個貌似要3.0才能用。所以蒐集下2.0中能使用的這些第三方庫。
AStar
A*尋路,常用的經典尋路演算法。
private astarTest() { //建立網格 let grid: AStarGrid = new AStarGrid(20, 20); //設定不可行走點 for (var i = 0; i < 100; i++) { grid.setWalkable(Math.floor(Math.random() * 20), Math.floor(Math.random() * 20), false); } //設定起點 grid.setStartNode(0, 0); //設定終點 grid.setEndNode(19, 19); //開始尋路 let aStar: AStar = new AStar(); if (aStar.findPath(grid)) { console.log("尋路成功,路徑點:", aStar.path); } else { console.log("尋路失敗"); } }
ProtoBuf
google開發用於通訊的序列化結構資料格式。
private protoTest() { let roomInfo: game.RoomInfo = new game.RoomInfo(); roomInfo.roomId = 123; let sendData = game.RoomInfo.encode(roomInfo).finish(); let revData = game.RoomInfo.decode(sendData); console.log(revData); }
搜尋
複製