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
81da815d
Commit
81da815d
authored
May 05, 2018
by
Mike Zhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: init RoomScene
parent
d3f5dd4b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
9 deletions
+82
-9
Main.ts
fe/src/Main.ts
+16
-7
Store.ts
fe/src/Store.ts
+3
-1
RoomScene.ts
fe/src/scenes/RoomScene.ts
+63
-1
No files found.
fe/src/Main.ts
View file @
81da815d
...
...
@@ -61,9 +61,12 @@ class Main extends egret.DisplayObjectContainer {
await
this
.
loadResource
()
var
stage
=
egret
.
MainContext
.
instance
.
stage
;
stage
.
setContentSize
(
1334
,
750
);
this
.
createGameScene
();
await
platform
.
login
();
const
userInfo
=
await
platform
.
getUserInfo
();
Store
.
onMessage
({
type
:
'setUserInfo'
,
data
:
userInfo
})
console
.
log
(
userInfo
);
platform
.
connectSocket
({
...
...
@@ -85,19 +88,25 @@ class Main extends egret.DisplayObjectContainer {
platform
.
onSocketOpen
(()
=>
{
platform
.
sendSocketMessage
({
data
:
JSON
.
stringify
({
cid
:
"asnbduawh"
,
seq
:
"moving"
,
x
:
100
,
y
:
123
type
:
'entry'
,
rid
:
'default_room'
,
payload
:
{
avatar_url
:
Store
.
getState
().
userInfo
.
avatarUrl
,
nick_name
:
Store
.
getState
().
userInfo
.
nickName
}
}),
success
:
()
=>
{
success
:
res
=>
{
console
.
error
(
"sendSocketMessage success"
)
},
fail
:
()
=>
{
fail
:
res
=>
{
console
.
error
(
"sendSocketMessage fail"
)
},
complete
:
res
=>
{
}
})
})
this
.
createGameScene
();
platform
.
onSocketMessage
(
function
(
res
)
{
console
.
log
(
'收到服务器内容:'
+
res
.
data
)
...
...
fe/src/Store.ts
View file @
81da815d
const
_state
=
{}
let
_state
:
any
=
{}
class
Store
{
static
getState
()
{
return
_state
...
...
@@ -11,6 +11,8 @@ class Store {
}
break
;
case
'setUserInfo'
:
_state
.
userInfo
=
message
.
data
default
:
break
;
}
...
...
fe/src/scenes/RoomScene.ts
View file @
81da815d
class
RoomScene
extends
egret
.
Sprite
{
private
startLabel
:
egret
.
TextField
private
players
:
Array
<
any
>
public
constructor
()
{
super
();
this
.
init
()
...
...
@@ -8,9 +11,68 @@ class RoomScene extends egret.Sprite {
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
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
}
private
initBg
()
{
var
shape
:
egret
.
Shape
=
new
egret
.
Shape
();
shape
.
graphics
.
beginFill
(
0x343E5F
);
shape
.
graphics
.
drawRect
(
0
,
0
,
2000
,
2000
);
shape
.
graphics
.
endFill
();
this
.
addChild
(
shape
);
var
bg
:
egret
.
Bitmap
=
new
egret
.
Bitmap
()
bg
.
texture
=
RES
.
getRes
(
"logo_jpg"
)
bg
.
scaleX
=
bg
.
scaleY
=
2
bg
.
x
=
1334
/
2
-
280
bg
.
y
=
100
this
.
addChild
(
bg
)
}
private
initStartLabel
()
{
this
.
startLabel
=
new
egret
.
TextField
()
this
.
startLabel
.
textColor
=
0xF0D66D
this
.
startLabel
.
text
=
"请稍等..."
this
.
startLabel
.
width
=
200
this
.
startLabel
.
anchorOffsetX
=
100
this
.
startLabel
.
x
=
1334
/
2
this
.
startLabel
.
textAlign
=
egret
.
HorizontalAlign
.
CENTER
;
this
.
startLabel
.
y
=
1136
/
2
}
private
startHandler
()
{
console
.
log
(
'starthandler'
)
SceneManager
.
getInstance
().
changeScene
(
'gameScene'
);
}
public
release
()
{
// 移除事件
}
...
...
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