2013-11-23 48 views
1

我正在開發具有在線遊戲模式的cocos2d-x遊戲。 由Photon Cloud SDK設計並實現的在線遊戲(http://www.exitgames.com)。 我只實現了ios版本,但它不起作用。 我已經實施的代碼很受打擊。IOS Photon Cloud SDK getRoomList函數不起作用

空隙NetworkLogic :: opJoinRandomRoom() {

ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList; 
roomList = mLoadBalancingClient.getRoomList(); 

int count = roomList.getSize(); 
CCLog("Room Count = %d", count); 
if(count == 0) 
{ 

    this->opCreateRoom(); 

}else{ 

    mLoadBalancingClient.opJoinRandomRoom(); 

} 

}

空隙NetworkLogic ::更新(浮動DT) {

this->run(); 

}

空隙NetworkLogic :: run(void) {

if(mLastInput == INPUT_EXIT && mStateAccessor.getState() != STATE_DISCONNECTING && mStateAccessor.getState() != STATE_DISCONNECTED) 
{ 
    disconnect(); 
    mStateAccessor.setState(STATE_DISCONNECTING); 
} 
else 
{ 
    State state = mStateAccessor.getState(); 
    switch(state) 
    { 
    case STATE_INITIALIZED: 
     connect(); 
     mStateAccessor.setState(STATE_CONNECTING); 
     break; 
    case STATE_CONNECTING: 
     break; // wait for callback 
    case STATE_CONNECTED: 
     { 
      ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList; 
      roomList = mLoadBalancingClient.getRoomList(); 

      int count = roomList.getSize(); 
      ExitGames::Common::JString tmp; 
      tmp = count; 
      EGLOG(ExitGames::Common::DebugLevel::INFO, tmp); 
      CCLog("Room count in Room = %d", count); 
      switch(mLastInput) 
      { 

       case INPUT_CREATE_GAME: // create Game 
        opCreateRoom(); 
        break; 
       case INPUT_JOIN_RANDOM_GAME: // join Game 
        opJoinRandomRoom(); 
        mStateAccessor.setState(STATE_JOINING); 
        break; 
       default: // no or illegal input -> stay waiting for legal input 
        break; 
      } 
      break; 
     } 
    case STATE_JOINING: 
     break; // wait for callback 
    case STATE_JOINED: 
     switch(mLastInput) 
     { 
     case INPUT_LEAVE_GAME: // leave Game 
      mLoadBalancingClient.opLeaveRoom(); 
      mStateAccessor.setState(STATE_LEAVING); 
      break; 
     default: // no or illegal input -> stay waiting for legal input 
      break; 
     } 
     break; 
    case STATE_LEAVING: 
     break; // wait for callback 
    case STATE_LEFT: 
     mStateAccessor.setState(STATE_CONNECTED); 
     break; 
    case STATE_DISCONNECTING: 
     break; // wait for callback 
    default: 
     break; 
    } 
} 
mLastInput = INPUT_NON; 
mLoadBalancingClient.service(); 

} 首先我運行一個應用程序,然後getRoomList函數返回0的值。 第一個房間創建並運行第二個應用程序後,但它也返回getRoomList函數0. 請幫助我。

回答

0

我剛剛採取了您在問題中提供的代碼,並將其複製到Photon C++ Client SDK的其他未更改的版本3.2.2.0版本的演示中的相應位置(並刪除了兩個CCLog()以使它無需cocos2d-x編譯),它對我來說工作得很好: 演示在房間列表的大小打印0,直到我讓一個客戶創建一個房間。之後其他客戶打印1.