我正在尝试实现GameManagerInterface并将其添加到GameManager但我总是得到下一个错误:
未捕获错误: 缺少player_available event.cast.receiver.games.j.hk的监听器方法@ cast_games_receiver.js:249
这是我的代码:
function GameManagerListener(){};
/*
* Fired when the game manager receives a request that changes game data (e.g.
* cast.receiver.games.GameManagerReceiverClient.sendGameDataRequest).
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameDataChanged = function(_event) {
console.info("[gameManagerListener][onGameDataChanged]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes gameplay
* state to cast.receiver.games.GameplayState.LOADING.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameLoading = function(_event) {
console.info("[gameManagerListener][onGameLoading]");
console.info(_event);
};
/*
* Fired when the game manager receives a game message (e.g. from
* cast.receiver.games.GameManagerReceiverClient.sendGameMessage).
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameMessageReceived = function(_event) {
console.info("[gameManagerListener][onGameMessageReceived]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes
* gameplay state to cast.receiver.games.GameplayState.PAUSED.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGamePaused = function(_event) {
console.info("[gameManagerListener][onGamePaused]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes gameplay
* state to cast.receiver.games.GameplayState.RUNNING.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameRunning = function(_event) {
console.info("[gameManagerListener][onGameRunning]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes gameplay
* state to cast.receiver.games.GameplayState.SHOWING_INFO_SCREEN.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameShowingInfoScreen = function(_event) {
console.info("[gameManagerListener][onGameShowingInfoScreen]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes game
* status text.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onGameStatusTextChanged = function(_event) {
console.info("[gameManagerListener][onGameStatusTextChanged]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes lobby
* state to cast.receiver.games.LobbyState.CLOSED.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onLobbyClosed = function(_event) {
console.info("[gameManagerListener][onLobbyClosed]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes lobby
* state to cast.receiver.games.LobbyState.OPEN.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onLobbyOpen = function(_event) {
console.info("[gameManagerListener][onLobbyOpen]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player
* state to cast.receiver.games.PlayerState.AVAILABLE.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerAvailable = function(_event) {
console.info("[gameManagerListener][onPlayerAvailable]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player data
* (e.g. cast.receiver.games.GameManagerReceiverClient.sendPlayerDataRequest).
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerDataChanged = function(_event) {
console.info("[gameManagerListener][onPlayerDataChanged]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes
* player state to cast.receiver.games.PlayerState.DROPPED.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerDropped = function(_event) {
console.info("[gameManagerListener][onPlayerDropped]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player
* state to cast.receiver.games.PlayerState.IDLE.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerIdle = function(_event) {
console.info("[gameManagerListener][onPlayerIdle]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player
* state to cast.receiver.games.PlayerState.PLAYING.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerPlaying = function(_event) {
console.info("[gameManagerListener][onPlayerPlaying]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player
* state to cast.receiver.games.PlayerState.QUIT.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerQuit = function(_event) {
console.info("[gameManagerListener][onPlayerQuit]");
console.info(_event);
};
/*
* Fired when the game manager receives a request that changes player
* state to cast.receiver.games.PlayerState.READY.
*
* @param {Event} _event Event used by cast.receiver.games.GameManager.
*/
GameManagerListener.prototype.onPlayerReady = function(_event) {
console.info("[gameManagerListener][onPlayerReady]");
console.info(_event);
};
但是如果我在添加GameManagerListener之前编写下一行,那么它可以工作..任何想法?谢谢。
this.gameManagerListener = new GameManagerListener();
this.gameManagerListener.gd = this.gameManagerListener.onPlayerAvailable;
this.gameManagerListener.nd = this.gameManagerListener.onPlayerReady;
this.gameManagerListener.kd = this.gameManagerListener.onPlayerIdle;
...