Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crazyflirt
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shawn Wang
crazyflirt
Commits
616e4cb8
Commit
616e4cb8
authored
May 05, 2018
by
Mike Zhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 使onSocketMessage通知更新Scene
parent
4af542f5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
29 deletions
+20
-29
Main.ts
fe/src/Main.ts
+8
-0
SceneManager.ts
fe/src/SceneManager.ts
+3
-3
RoomScene.ts
fe/src/scenes/RoomScene.ts
+9
-26
No files found.
fe/src/Main.ts
View file @
616e4cb8
...
...
@@ -111,6 +111,14 @@ class Main extends egret.DisplayObjectContainer {
platform
.
onSocketMessage
(
function
(
res
)
{
console
.
log
(
'收到服务器内容:'
+
res
.
data
)
const
state
=
Store
.
onMessage
(
res
.
data
)
let
data
=
res
.
data
if
(
typeof
res
.
data
===
'string'
)
{
data
=
JSON
.
parse
(
res
.
data
)
}
if
(
data
.
type
===
'entry'
)
{
SceneManager
.
getInstance
().
roomScene
.
update
(
data
)
}
})
platform
.
onSocketError
((
e
)
=>
{
console
.
error
(
"onSocketError"
)
...
...
fe/src/SceneManager.ts
View file @
616e4cb8
...
...
@@ -2,9 +2,9 @@ class SceneManager extends egret.DisplayObjectContainer {
// 场景控制器的单例
private
static
instance
:
SceneManager
;
// 开始场景
p
rivate
roomScene
:
RoomScene
;
p
ublic
roomScene
:
RoomScene
;
// 游戏场景
p
rivate
gameScene
:
GameScene
;
p
ublic
gameScene
:
GameScene
;
public
constructor
()
{
super
();
...
...
@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this
.
roomScene
=
new
RoomScene
();
this
.
gameScene
=
new
GameScene
();
// 默认添加开始场景
this
.
addChild
(
this
.
game
Scene
);
this
.
addChild
(
this
.
room
Scene
);
}
// 实例化单例获取方法
public
static
getInstance
():
SceneManager
{
...
...
fe/src/scenes/RoomScene.ts
View file @
616e4cb8
...
...
@@ -13,37 +13,20 @@ class RoomScene extends egret.Sprite {
console
.
log
(
'RoomScene.init'
)
this
.
initBg
()
this
.
initStartLabel
()
// platform.sendSocketMessage({
// data: JSON.stringify({
// type: 'entry',
// rid: 'default_room',
// payload: {
// avatar_url: Store.getState().userInfo.avatarUrl,
// nick_name: Store.getState().userInfo.nickName
// }
// }),
// success: res => {
// console.error("sendSocketMessage success")
// },
// fail: res => {
// console.error("sendSocketMessage fail")
// },
// complete: res => {
// }
// })
platform
.
onSocketMessage
(
res
=>
{
if
(
res
.
type
===
'entry'
)
{
console
.
log
(
'get entry data'
)
}
})
// this.startLabel.text = "START";
this
.
startLabel
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_TAP
,
this
.
startHandler
,
this
);
this
.
addChild
(
this
.
startLabel
);
// put display object to this scene
}
public
update
(
data
)
{
const
payload
=
data
.
payload
if
(
payload
.
seat
==
0
)
{
this
.
startLabel
.
text
=
'开始'
this
.
startLabel
.
touchEnabled
=
true
this
.
startLabel
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_TAP
,
this
.
startHandler
,
this
)
}
}
private
initBg
()
{
var
shape
:
egret
.
Shape
=
new
egret
.
Shape
();
shape
.
graphics
.
beginFill
(
0x343E5F
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment