SlideShare una empresa de Scribd logo
1 de 20
網路遊戲設計 Web Game Design 授課教師 江素貞
Chapter 5 Chat First Chat Project
Create Login UI 宣告LoginScreen類別(LoginScreen.as),於建構子中載入SWF檔 讀取檔案資訊 (loader為 Loader物件) loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getComponents); public function getComponents(e:Event):void 	{ 		var info:LoaderInfo = e.target as LoaderInfo; 		var loader:Loader = info.loader as Loader; 		var a:MovieClip = loader.getChildAt(0) as MovieClip; 		var myMC:MovieClip = a.getChildAt(0) as MovieClip; 		loader.x = stage.stageWidth / 2 - info.width/2;	//info內含影片片段Size 		loader.y = stage.stageHeight / 2 - info.height/2; 		myMC.name_txt.text = "player" + Math.round(10000 * Math.random()); 	}
Create Login Screen(Dispatch Message) ,[object Object],	public varlogin_btn:Button; 	 	public static varOK:String=“OK”;	//定義事件名稱 	public function getComponents(e:Event):void 	{ 		…… login_btn = myMC.login_btn; login_btn.addEventListener(MouseEvent.CLICK, onClick); 	} 	public function onClick(e:MouseEvent) 	{ dispatchEvent(new Event(OK)); 	}
Create Login UI(Listen Event) var login:LoginScreen = new LoginScreen(); login.addEventListener(LoginScreen.OK, onLoginToServer);
Chat
使用者清單與訊息傳送 ConnServer中,登入成功時建立Chat物件(將ElectroServer instance傳入),接手處理訊息工作 ChatScreen類別為顯示聊天畫面 載入完成時派送”OK”訊息 按下[send]按鈕時派送”MSG”訊息 Chat.as:處理訊息 顯示聊天畫面 收到”OK”訊息時,讓使用者進入預設的Lobby房間 進入房間後顯示自己的名字及玩家清單 收到”MSG”訊息時,傳送訊息 收到PublicMessageEvent訊息時, 顯示訊息
MessageType Properties UserListUpdateEvent: 房間內有新玩家進入時觸發 ZoneUpdateEvent:Zone裡有房間被創造出來時觸發 PublicMessageRequest PublicMessageEvent CreateRoomRequest JoinRoomEvent 				    ZoneUpdateEvent
Show Chat UI Chatconstrucor chatScreen= new ChatScreen(); addChild(chatScreen); chatScreen.addEventListener(ChatScreen.OK, onChatScreenReady); chatScreen.addEventListener(ChatScreen.MSG, onChat);
Enter Lobby Room private function JoinRoom(roomName:String):void { varcrr:CreateRoomRequest = new CreateRoomRequest(); crr.setRoomName(roomName); crr.setZoneName("chat"); es.send(crr); }
Who Am I ,[object Object]
Example:	The es is a ElectroServer instance. es.getUserManager().getMe().getUserName() ,[object Object]
getMe(): Gets User that represents you.,[object Object]
Show User List 加入房間成功時呼叫 showUserList() 接收到 UserListUpdateEvent 時呼叫 showUserList() es.addEventListener(MessageType.UserListUpdateEvent, 	"onUserListUpdate", this); 	public function onUserListUpdate(ev:UserListUpdateEvent) 	{ showUserList(); 	}
Send Public Message varpmr:PublicMessageRequest = new PublicMessageRequest(); pmr.setMessage(chatScreen.chatInput_txt.text); pmr.setRoomId(room.getRoomId()); pmr.setZoneId(room.getZoneId());			 es.send(pmr); ,[object Object],[object Object]
偵測使用者進入或離開 public function onUserListUpdate(ev:UserListUpdateEvent) { 	//ev提供相關函式,可取得造成user list變更的使用者資訊 	if (ev.getActionId() == UserListUpdateEvent.DeleteUser){ 		//使用者離開 	} 	if (ev.getActionId() == UserListUpdateEvent.AddUser) { 		//使用者進入 	} }
設定TextArea之文字顏色 private function appendMessage(msg:String, color:String="#000000") { varmsgStr:String = "<font color='" + color + "'>" + msg + "</font>"; chatScreen.chatList_txt.htmlText+=(msgStr); }
Show Room List private function showRoomList() { varrooms:Array = 	es.getZoneManager().getZoneByName("chat").getRooms(); chatScreen.room_list.removeAll(); 	for (vari in rooms) { varrm:Room = rooms[i] as Room; var lab=rm.getRoomName()+"("+rm.getUserCount()+")“; chatScreen.room_list.addItem( { label:lab, data:rm } ); chatScreen.room_list.sortItemsOn("label", "ASC");  	} }
加入房間 public function onChangeRoom(e:Event){ varrm:Room = chatScreen.room_list.selectedItem.data; 	if (rm.getUserCount() == rm.getCapacity()) { 		//房間已滿 	} 	else{ leaveCurrentRoom();		//離開房間 JoinRoom(rm.getRoomName()); 	} }
離開房間 private function leaveCurrentRoom() { varlc:LeaveRoomRequest = new LeaveRoomRequest(); lc.setRoomId( myRoom.getRoomId() ); lc.setZoneId( myRoom.getZoneId() );	 es.send(lc); } ,[object Object]

Más contenido relacionado

Similar a Les 4 ppt

Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash AppsOwasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
guestb0af15
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
Robert Nyman
 
Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Robert Nyman
 
AIR 開發應用程式實務
AIR 開發應用程式實務AIR 開發應用程式實務
AIR 開發應用程式實務
angelliya00
 
Using AIR for Mobile Development
Using AIR for Mobile DevelopmentUsing AIR for Mobile Development
Using AIR for Mobile Development
Veronique Brossier
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
Robert Nyman
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
Robert Nyman
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
Robert Nyman
 

Similar a Les 4 ppt (20)

17 camera, media, and audio in windows phone 8.1
17   camera, media, and audio in windows phone 8.117   camera, media, and audio in windows phone 8.1
17 camera, media, and audio in windows phone 8.1
 
Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash AppsOwasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
Owasp Wasc App Sec2007 San Jose Finding Vulnsin Flash Apps
 
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
 Cutting edge HTML5 API you can use today (by Bohdan Rusinka) Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
Cutting edge HTML5 API you can use today (by Bohdan Rusinka)
 
Moustamera
MoustameraMoustamera
Moustamera
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
 
How to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NETHow to implement camera recording for USB webcam or IP camera in C#.NET
How to implement camera recording for USB webcam or IP camera in C#.NET
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
 
AIR 開發應用程式實務
AIR 開發應用程式實務AIR 開發應用程式實務
AIR 開發應用程式實務
 
Using AIR for Mobile Development
Using AIR for Mobile DevelopmentUsing AIR for Mobile Development
Using AIR for Mobile Development
 
Virus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing GatekeeperVirus Bulletin 2015: Exposing Gatekeeper
Virus Bulletin 2015: Exposing Gatekeeper
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
 
Abusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS appsAbusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS apps
 
Flash Widget Tutorial
Flash Widget TutorialFlash Widget Tutorial
Flash Widget Tutorial
 
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, MoscowJavaScript APIs - The Web is the Platform - .toster conference, Moscow
JavaScript APIs - The Web is the Platform - .toster conference, Moscow
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
 
20141030 html5j-firefox os-deviceapi
20141030 html5j-firefox os-deviceapi20141030 html5j-firefox os-deviceapi
20141030 html5j-firefox os-deviceapi
 
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM EuropeBlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
 
Skinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsSkinning Android for Embedded Applications
Skinning Android for Embedded Applications
 
IOMX in Android
IOMX in AndroidIOMX in Android
IOMX in Android
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

Les 4 ppt

  • 1. 網路遊戲設計 Web Game Design 授課教師 江素貞
  • 2. Chapter 5 Chat First Chat Project
  • 3. Create Login UI 宣告LoginScreen類別(LoginScreen.as),於建構子中載入SWF檔 讀取檔案資訊 (loader為 Loader物件) loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getComponents); public function getComponents(e:Event):void { var info:LoaderInfo = e.target as LoaderInfo; var loader:Loader = info.loader as Loader; var a:MovieClip = loader.getChildAt(0) as MovieClip; var myMC:MovieClip = a.getChildAt(0) as MovieClip; loader.x = stage.stageWidth / 2 - info.width/2; //info內含影片片段Size loader.y = stage.stageHeight / 2 - info.height/2; myMC.name_txt.text = "player" + Math.round(10000 * Math.random()); }
  • 4.
  • 5. Create Login UI(Listen Event) var login:LoginScreen = new LoginScreen(); login.addEventListener(LoginScreen.OK, onLoginToServer);
  • 7. 使用者清單與訊息傳送 ConnServer中,登入成功時建立Chat物件(將ElectroServer instance傳入),接手處理訊息工作 ChatScreen類別為顯示聊天畫面 載入完成時派送”OK”訊息 按下[send]按鈕時派送”MSG”訊息 Chat.as:處理訊息 顯示聊天畫面 收到”OK”訊息時,讓使用者進入預設的Lobby房間 進入房間後顯示自己的名字及玩家清單 收到”MSG”訊息時,傳送訊息 收到PublicMessageEvent訊息時, 顯示訊息
  • 8. MessageType Properties UserListUpdateEvent: 房間內有新玩家進入時觸發 ZoneUpdateEvent:Zone裡有房間被創造出來時觸發 PublicMessageRequest PublicMessageEvent CreateRoomRequest JoinRoomEvent ZoneUpdateEvent
  • 9. Show Chat UI Chatconstrucor chatScreen= new ChatScreen(); addChild(chatScreen); chatScreen.addEventListener(ChatScreen.OK, onChatScreenReady); chatScreen.addEventListener(ChatScreen.MSG, onChat);
  • 10. Enter Lobby Room private function JoinRoom(roomName:String):void { varcrr:CreateRoomRequest = new CreateRoomRequest(); crr.setRoomName(roomName); crr.setZoneName("chat"); es.send(crr); }
  • 11.
  • 12.
  • 13.
  • 14. Show User List 加入房間成功時呼叫 showUserList() 接收到 UserListUpdateEvent 時呼叫 showUserList() es.addEventListener(MessageType.UserListUpdateEvent, "onUserListUpdate", this); public function onUserListUpdate(ev:UserListUpdateEvent) { showUserList(); }
  • 15.
  • 16. 偵測使用者進入或離開 public function onUserListUpdate(ev:UserListUpdateEvent) { //ev提供相關函式,可取得造成user list變更的使用者資訊 if (ev.getActionId() == UserListUpdateEvent.DeleteUser){ //使用者離開 } if (ev.getActionId() == UserListUpdateEvent.AddUser) { //使用者進入 } }
  • 17. 設定TextArea之文字顏色 private function appendMessage(msg:String, color:String="#000000") { varmsgStr:String = "<font color='" + color + "'>" + msg + "</font>"; chatScreen.chatList_txt.htmlText+=(msgStr); }
  • 18. Show Room List private function showRoomList() { varrooms:Array = es.getZoneManager().getZoneByName("chat").getRooms(); chatScreen.room_list.removeAll(); for (vari in rooms) { varrm:Room = rooms[i] as Room; var lab=rm.getRoomName()+"("+rm.getUserCount()+")“; chatScreen.room_list.addItem( { label:lab, data:rm } ); chatScreen.room_list.sortItemsOn("label", "ASC"); } }
  • 19. 加入房間 public function onChangeRoom(e:Event){ varrm:Room = chatScreen.room_list.selectedItem.data; if (rm.getUserCount() == rm.getCapacity()) { //房間已滿 } else{ leaveCurrentRoom(); //離開房間 JoinRoom(rm.getRoomName()); } }
  • 20.