Google Play游戏服务。(Google Play Game Services. Real Time Skeleton Application. Player presses back butt

编程入门 行业动态 更新时间:2024-10-27 19:15:35
Google Play游戏服务。(Google Play Game Services. Real Time Skeleton Application. Player presses back button in waiting room)

我正在使用Google Play服务的实时骨架(按钮点击器示例)解决我遇到的问题。 我注意到,如果玩家1在等候室中通过按下后退按钮离开房间之前玩家2接受了玩家2仍然连接的邀请并且mParticipants的值在玩家2方仍然是2,即使玩家1本应该离开房间。

示例(玩家1邀请玩家2参加比赛。等候室打开。):

08-05 17:24:41.886: D/GameHelper(22237): GameHelper: onActivityResult: req=10000, resp=RESULT_OK 08-05 17:24:41.886: D/GameHelper(22237): GameHelper: onActivityResult: request code not meant for us. Ignoring. 08-05 17:24:41.886: D/ButtonClicker2000(22237): Select players UI succeeded. 08-05 17:24:41.886: D/ButtonClicker2000(22237): Invitee count: 1 08-05 17:24:41.886: D/ButtonClicker2000(22237): Creating room... 08-05 17:24:41.906: D/ButtonClicker2000(22237): Room created, waiting for it to be ready... 08-05 17:24:43.257: D/ButtonClicker2000(22237): onRoomCreated(0, RoomEntity{RoomId=ChEKCQjEutW5sAUQAhABGAAgARDq9JSasuOhhvcB, CreatorId=p_COr0lJqy46GG9wEQAQ, CreationTimestamp=1407284683121, RoomStatus=0, Description=null, Variant=0, AutoMatchCriteria=null, Participants=[ParticipantEntity{ParticipantId=p_COr0lJqy46GG9wEQAg, Player=PlayerEntity{PlayerId=116552246986005424427, DisplayName=Chris Sepich, IconImageUri=null, IconImageUrl=null, HiResImageUri=null, HiResImageUrl=null, RetrievedTimestamp=1407284683152}, Status=1, ClientAddress=null, ConnectedToRoom=false, DisplayName=Chris Sepich, IconImage=null, IconImageUrl=null, HiResImage=null, HiResImageUrl=null, Capabilities=0, Result=null}, ParticipantEntity{ParticipantId=p_COr0lJqy46GG9wEQAQ, Player=PlayerEntity{PlayerId=113875263239226324701, DisplayName=Eric Sepich, IconImageUri=content://com.google.android.gms.games.background/images/80784b26/2, IconImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns/, HiResImageUri=content://com.google.android.gms.games.background/images/80784b26/7, HiResImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns-s376/, RetrievedTimestamp=1407284683151}, Status=2, ClientAddress=null, ConnectedToRoom=false, DisplayName=Eric Sepich, IconImage=content://com.google.android.gms.games.background/images/80784b26/2, IconImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns/, HiResImage=content://com.google.android.gms.games.background/images/80784b26/7, HiResImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns-s376/, Capabilities=0, Result=null}], AutoMatchWaitEstimateSeconds=-1})

示例(在候诊室中。播放器1按下后退按钮。运行leaveRoom())

08-05 17:24:46.330: D/GameHelper(22237): GameHelper: onActivityResult: req=10002, resp=RESULT_CANCELED 08-05 17:24:46.330: D/GameHelper(22237): GameHelper: onActivityResult: request code not meant for us. Ignoring. 08-05 17:24:46.330: D/ButtonClicker2000(22237): Leaving room.

当玩家2接受邀请时,我已经检查了玩家2的申请中的mParticipants的长度:

@Override public void onConnectedToRoom(Room room) { Log.d(TAG, "onConnectedToRoom."); // get room ID, participants and my ID: mRoomId = room.getRoomId(); mParticipants = room.getParticipants(); mMyId = room.getParticipantId(Games.Players.getCurrentPlayerId(getApiClient())); Log.d(TAG, "mParticipants.size():"+mParticipants.size()); // print out the list of participants (for debug purposes) Log.d(TAG, "Room ID: " + mRoomId); Log.d(TAG, "My ID " + mMyId); Log.d(TAG, "<< CONNECTED TO ROOM>>"); }

mParticipants数组的长度仍为2,即使玩家1应该在此时离开房间。 我发布这是一个问题,看看是否有其他人处理过同样的问题。 我希望检查onConnectedToRoom()中的参与者数量,如果其中一个玩家按下等候室中的后退按钮,则应终止匹配并将用户发送回主屏幕。 为什么mParticipants的长度仍然是2,并且有没有办法处理这种情况,其中一个玩家按下了等候室内的后退按钮?

我在连接播放器下找到了文档,但我仍然无法解决问题。 基本上我所说的是在迭代之后:

Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoomId);

另一个客户端仍然连接,好像玩家还在房间里,因为在等候室按下了后退按钮。 有补救措施吗?

谢谢

I'm troubleshooting an issue I'm having with the real time skeleton (Button clicker example) for Google Play Services. I'm noticing that if player 1 while in the waiting room leaves the room by way of pressing the back button before player 2 accepts the invitation that player 2 is still connected and the value of mParticipants is still 2 on the player 2 side even though player 1 is supposed to have left the room.

Example (Player 1 invites player 2 to a match. The waiting room is opened.):

08-05 17:24:41.886: D/GameHelper(22237): GameHelper: onActivityResult: req=10000, resp=RESULT_OK 08-05 17:24:41.886: D/GameHelper(22237): GameHelper: onActivityResult: request code not meant for us. Ignoring. 08-05 17:24:41.886: D/ButtonClicker2000(22237): Select players UI succeeded. 08-05 17:24:41.886: D/ButtonClicker2000(22237): Invitee count: 1 08-05 17:24:41.886: D/ButtonClicker2000(22237): Creating room... 08-05 17:24:41.906: D/ButtonClicker2000(22237): Room created, waiting for it to be ready... 08-05 17:24:43.257: D/ButtonClicker2000(22237): onRoomCreated(0, RoomEntity{RoomId=ChEKCQjEutW5sAUQAhABGAAgARDq9JSasuOhhvcB, CreatorId=p_COr0lJqy46GG9wEQAQ, CreationTimestamp=1407284683121, RoomStatus=0, Description=null, Variant=0, AutoMatchCriteria=null, Participants=[ParticipantEntity{ParticipantId=p_COr0lJqy46GG9wEQAg, Player=PlayerEntity{PlayerId=116552246986005424427, DisplayName=Chris Sepich, IconImageUri=null, IconImageUrl=null, HiResImageUri=null, HiResImageUrl=null, RetrievedTimestamp=1407284683152}, Status=1, ClientAddress=null, ConnectedToRoom=false, DisplayName=Chris Sepich, IconImage=null, IconImageUrl=null, HiResImage=null, HiResImageUrl=null, Capabilities=0, Result=null}, ParticipantEntity{ParticipantId=p_COr0lJqy46GG9wEQAQ, Player=PlayerEntity{PlayerId=113875263239226324701, DisplayName=Eric Sepich, IconImageUri=content://com.google.android.gms.games.background/images/80784b26/2, IconImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns/, HiResImageUri=content://com.google.android.gms.games.background/images/80784b26/7, HiResImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns-s376/, RetrievedTimestamp=1407284683151}, Status=2, ClientAddress=null, ConnectedToRoom=false, DisplayName=Eric Sepich, IconImage=content://com.google.android.gms.games.background/images/80784b26/2, IconImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns/, HiResImage=content://com.google.android.gms.games.background/images/80784b26/7, HiResImageUrl=http://lh3.googleusercontent.com/-udm-yatehyg/AAAAAAAAAAI/AAAAAAAAABw/w0iPFPD2Ijs/s96-ns-s376/, Capabilities=0, Result=null}], AutoMatchWaitEstimateSeconds=-1})

Example (While in the waiting room. Player 1 presses the back button. leaveRoom() is run)

08-05 17:24:46.330: D/GameHelper(22237): GameHelper: onActivityResult: req=10002, resp=RESULT_CANCELED 08-05 17:24:46.330: D/GameHelper(22237): GameHelper: onActivityResult: request code not meant for us. Ignoring. 08-05 17:24:46.330: D/ButtonClicker2000(22237): Leaving room.

When player 2 accepts the invitation I have checked the length of mParticipants in player 2's application inside of:

@Override public void onConnectedToRoom(Room room) { Log.d(TAG, "onConnectedToRoom."); // get room ID, participants and my ID: mRoomId = room.getRoomId(); mParticipants = room.getParticipants(); mMyId = room.getParticipantId(Games.Players.getCurrentPlayerId(getApiClient())); Log.d(TAG, "mParticipants.size():"+mParticipants.size()); // print out the list of participants (for debug purposes) Log.d(TAG, "Room ID: " + mRoomId); Log.d(TAG, "My ID " + mMyId); Log.d(TAG, "<< CONNECTED TO ROOM>>"); }

The length of the mParticipants array is still reading as 2 even though player 1 is supposed to have left the room at this point. I'm posting this as a question to see if anyone else has dealt with the same issue. I was hoping to check the number of participants in onConnectedToRoom() and if one of the players has pressed the back button in the waiting room the match should be terminated and the user sent back to the main screen. Why is the length of mParticipants still 2 here and is there a way to handle this occurrence where one of the players has pressed the back button inside the waiting room?

I've found the documentation under connecting players but I'm still unable to resolve the problem. Essentially what I'm saying is that after an iteration of:

Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoomId);

The other client still connects as if the player were still in the room because the back button was pressed in the waiting room. Is there a remedy?

Thank you

最满意答案

mParticipants的长度不是您要查找的值。 玩家永远不会从mParticipants中移除,他们只是改变状态。 离开的参与者将有com.google.android.gms.games.multiplayer.Participant.STATUS_LEFT。

The length of mParticipants isn't the value you're looking for. Players are never removed from mParticipants, they just change state. The Participant that left will have com.google.android.gms.games.multiplayer.Participant.STATUS_LEFT.

更多推荐

本文发布于:2023-07-05 01:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游戏   Services   Time   Real   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!