2014-06-26 155 views
0

我一直在尋找幾個小時,我無法在互聯網上找到答案...希望你們能幫助我。Android Google Play遊戲服務startQuickGame,undefined makeBasicRoomConfigBuilder()

我想要實現在谷歌Play遊戲服務快速遊戲: https://developers.google.com/games/services/android/realtimeMultiplayer

我也跟着在谷歌網站上的說明。在我的應用程序中使用Google帳戶登錄成功。現在我想實現一個簡單的遊戲,但有一條錯誤信息:

makeBasicRoomConfigBuilder(); 

的方法makeBasicRoomConfigBuilder();是未定義類型GameActivity

下面是我的一些代碼:

import com.android.vending.billing.IInAppBillingService; 
import com.google.android.gms.ads.*; 
import com.google.android.gms.common.api.*; 
import com.google.android.gms.games.Games; 
import com.google.android.gms.games.multiplayer.realtime.RoomConfig; 
import com.google.example.games.basegameutils.BaseGameActivity; 


public class GameActivity extends BaseGameActivity { 

    private static InterstitialAd interstitial; 
    private AdView adView; 
    private int FieldWidth; 
    private int FieldHeight; 
    private EditText playerEdit; 
    private Button settingsSave; 
    private GameView theGameView; 
    private static SoundPool soundPool; 
    private static HashMap<Integer, Integer> soundsMap; 
    IInAppBillingService mService; 
    private Sql2Player SqlArray2Player; 
    private Sql3Player SqlArray3Player; 
    private SqlQPlayer SqlArrayQPlayer; 
    public ConnectivityManager conMgr; 
    public GameLoopThread theGameLoopThread; 

    private void startQuickGame() { 
     // auto-match criteria to invite one random automatch opponent. 
     // You can also specify more opponents (up to 3). 
     Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0); 

     // build the room config: 
     RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder(); 
     roomConfigBuilder.setAutoMatchCriteria(am); 
     RoomConfig roomConfig = roomConfigBuilder.build(); 

     // create room: 
     Games.RealTimeMultiplayer.create(getApiClient(), roomConfig); 

    } 

.... 

任何想法?

謝謝!

回答

1

這從https://developers.google.com/games/services/android/troubleshooting

聽衆不叫

失蹤多人的聽衆

多人遊戲通常需要設立聽衆如RoomUpdateListener,RoomStatusUpdateListener和RealTimeMessageReceivedListener。

使用此偵聽器時常見的錯誤是忘記將它們添加到設置多人遊戲的所有代碼路徑上的RoomConfig對象。

我們建議您編寫創建與適當的回調一個RoomConfig.Builder一個輔助方法:

private RoomConfig.Builder makeBasicRoomConfigBuilder() { 
    RoomConfig.Builder builder = RoomConfig.builder(this); 
    builder.setMessageReceivedListener(this); 
    builder.setRoomStatusUpdateListener(this); 

    // ...add other listeners as needed... 

    return builder; 
} 

然後,使用這種方法每次你成立一個多人遊戲,而不是設定的時間手動調用回調。你必須這樣做,你在哪裏開始多人遊戲,無論您是創建或加入一個房間的所有方案。」

我懷疑你的代碼只是缺少一個或多個聽衆。我沒有寫。在我的應用程序一個輔助方法相反,我建議你看看ButtonClicker樣品,你會看到一個更簡單的方法:

https://github.com/playgameservices/android-samples/tree/master/eclipse_compat/ButtonClicker