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

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

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.