SmartFoxServer 2X Room的加入與建立
生活随笔
收集整理的這篇文章主要介紹了
SmartFoxServer 2X Room的加入與建立
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
SmartFoxServer 2X Room的加入與建立
On 2011/08/03, in SmartFoxServer 2X, by AllenRoom的型態(tài)有二種
- 靜態(tài)Room:Zone Configurator裡設定,當sfs啟動時,Server端會建立靜態(tài)Room,適用大廳、固定的聊天室
- 動態(tài)Room:sfs運作期間,可由Server端或Client端建立,適用新開戰(zhàn)場、新開聊天室
sfs裡加入、離開、建立Room等
跟遊戲架構觀念相同
可以很靈活地取得不同範圍的資料
Room還可分為一般跟遊戲(Room屬性isGame)
- 一般Room:普通的聊天室、大廳等
- 遊戲Room:專為遊戲房間設計,會自動指定player id,以容易判斷房間內(nèi)的user,及允許旁觀者(spectators)進來
?
Client端進入Room請求
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var sfs:SmartFox = new SmartFox(); sfs.addEventListener(SFSEvent.ROOM_JOIN, onJoin); sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onJoinError); sfs.send( new JoinRoomRequest("The Lobby") ); public function onJoin(evt:SFSEvent):void { trace("Joined Room: " + evt.params.room.name); } public function onJoinError(evt:SFSEvent):void { trace("Join failed: " + evt.params.errorMessage); } |
Server端指定user進入Room
| 1 2 3 4 5 6 7 | User user = (User) event.getParameter(SFSEventParam.USER); Room Lobby = getParentExtension().getParentZone().getRoomByName("The Lobby"); if (Lobby == null) throw new SFSException("沒有 Lobby 房間"); getApi().joinRoom(user, Lobby); |
Client端建立Room
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | smartFox.addEventListener(SFSEvent.ROOM_ADD, onRoomAdded) smartFox.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError) // Create a new Chat Room var settings:RoomSettings = new RoomSettings("Piggy's Chat Room") settings.maxUsers = 40 settings.groupId = "ChatGroup" smartFox.send(new CreateRoomRequest(settings)) function onRoomAdded(evt:SFSEvent):void { trace("A new Room was added: " + evt.params.room ) } function onRoomCreationError(evt:SFSEvent):void { trace("An error occurred while attempting to create the Room: " + evt.params.errorMessage) } |
參考資料:
SFS2X Docs / DevelopmentBasics / join-and-create-rooms
轉載于:https://www.cnblogs.com/88999660/articles/2889268.html
總結
以上是生活随笔為你收集整理的SmartFoxServer 2X Room的加入與建立的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何将 backordered 的SO#
- 下一篇: HDOJ 3255 Farming(扫描