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
2aee812d
Commit
2aee812d
authored
May 05, 2018
by
Shawn Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
socket and control
parent
71d6bd0d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
8 deletions
+184
-8
Controller.ts
fe/src/Controller.ts
+66
-0
Main.ts
fe/src/Main.ts
+62
-6
Platform.ts
fe/src/Platform.ts
+38
-0
GameScene.ts
fe/src/scenes/GameScene.ts
+5
-1
native_require.js
fe/template/runtime/native_require.js
+13
-1
No files found.
fe/src/Controller.ts
0 → 100644
View file @
2aee812d
class
Controller
extends
egret
.
Sprite
{
public
constructor
()
{
super
();
this
.
init
()
}
private
speed
=
10
private
speedX
=
0
private
speedY
=
0
private
p1
:
egret
.
Point
=
new
egret
.
Point
();
private
p2
:
egret
.
Point
=
new
egret
.
Point
();
private
control
=
new
egret
.
Shape
();
private
pointtt
=
new
egret
.
Shape
();
private
controlCenter
=
new
egret
.
Point
(
1100
,
450
)
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
this
.
control
.
graphics
.
beginFill
(
0xFF3866
,
1
);
this
.
control
.
graphics
.
drawCircle
(
1100
,
450
,
90
);
this
.
control
.
graphics
.
endFill
();
this
.
addChild
(
this
.
control
);
this
.
pointtt
.
graphics
.
beginFill
(
0xFF0000
,
1
)
this
.
pointtt
.
graphics
.
drawCircle
(
1100
,
450
,
10
)
this
.
pointtt
.
graphics
.
endFill
()
this
.
addChild
(
this
.
pointtt
)
this
.
touchEnabled
=
true
this
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_BEGIN
,
this
.
controlTouchBegin
,
this
)
this
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_MOVE
,
this
.
controlTouchMove
,
this
)
this
.
addEventListener
(
egret
.
TouchEvent
.
TOUCH_END
,
this
.
controlTouchEnd
,
this
)
this
.
addEventListener
(
egret
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
)
}
private
onEnterFrame
(
e
:
egret
.
Event
){
if
(
this
.
touchEnd
){
return
}
this
.
pointtt
.
x
+=
this
.
speedX
this
.
pointtt
.
y
+=
this
.
speedY
}
private
touchEnd
=
false
private
controlTouchBegin
(
e
:
egret
.
TouchEvent
){
this
.
touchEnd
=
false
}
private
controlTouchMove
(
e
:
egret
.
TouchEvent
){
var
angle
=
Math
.
atan2
(
e
.
stageY
-
this
.
controlCenter
.
y
,
e
.
stageX
-
this
.
controlCenter
.
x
)
// console.error(e)
this
.
speedX
=
Math
.
cos
(
angle
)
*
this
.
speed
;
this
.
speedY
=
Math
.
sin
(
angle
)
*
this
.
speed
;
// console.error(this.speedX)
// console.error(e.stageX)
}
private
controlTouchEnd
(
e
:
egret
.
TouchEvent
){
this
.
touchEnd
=
true
// this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
}
public
release
()
{
// 移除事件
}
}
\ No newline at end of file
fe/src/Main.ts
View file @
2aee812d
...
...
@@ -55,19 +55,62 @@ class Main extends egret.DisplayObjectContainer {
this
.
runGame
().
catch
(
e
=>
{
console
.
log
(
e
);
})
}
private
async
runGame
()
{
await
this
.
loadResource
()
var
stage
=
egret
.
MainContext
.
instance
.
stage
;
stage
.
setContentSize
(
1334
,
750
);
this
.
createGameScene
();
const
result
=
await
RES
.
getResAsync
(
"description_json"
)
await
platform
.
login
();
const
userInfo
=
await
platform
.
getUserInfo
();
console
.
log
(
userInfo
);
platform
.
connectSocket
({
url
:
"ws://192.168.50.118:9090"
,
header
:
{
'content-type'
:
'application/json'
},
method
:
"GET"
,
success
:
(...
args
)
=>
{
console
.
error
(
"success"
)
console
.
error
(
args
)
},
fail
:
(...
args
)
=>
{
console
.
error
(
"fail"
)
console
.
error
(
args
)
}
})
platform
.
onSocketOpen
(()
=>
{
platform
.
sendSocketMessage
({
data
:
JSON
.
stringify
({
cid
:
"asnbduawh"
,
seq
:
"moving"
,
x
:
100
,
y
:
123
}),
success
:
()
=>
{
console
.
error
(
"sendSocketMessage success"
)
},
fail
:
()
=>
{
console
.
error
(
"sendSocketMessage fail"
)
}
})
})
platform
.
onSocketMessage
(
function
(
res
)
{
console
.
log
(
'收到服务器内容:'
+
res
.
data
)
})
platform
.
onSocketError
((
e
)
=>
{
console
.
error
(
"onSocketError"
)
console
.
error
(
e
)
})
platform
.
onSocketClose
((
e
)
=>
{
console
.
error
(
"onSocketClose"
)
console
.
error
(
e
)
})
}
private
async
loadResource
()
{
...
...
@@ -83,6 +126,9 @@ class Main extends egret.DisplayObjectContainer {
}
}
private
textfield
:
egret
.
TextField
;
private
myPosition
=
new
egret
.
Point
(
0
,
0
)
/**
* 创建游戏场景
* Create a game scene
...
...
@@ -90,5 +136,16 @@ class Main extends egret.DisplayObjectContainer {
private
createGameScene
()
{
this
.
addChild
(
SceneManager
.
getInstance
());
}
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
private
createBitmapByName
(
name
:
string
)
{
let
result
=
new
egret
.
Bitmap
();
let
texture
:
egret
.
Texture
=
RES
.
getRes
(
name
);
result
.
texture
=
texture
;
return
result
;
}
}
\ No newline at end of file
}
fe/src/Platform.ts
View file @
2aee812d
...
...
@@ -10,15 +10,53 @@ declare interface Platform {
login
():
Promise
<
any
>
connectSocket
(
options
):
void
onSocketOpen
(
callback
):
void
onSocketClose
(
callback
):
void
onSocketMessage
(
callback
):
void
onSocketError
(
callback
):
void
sendSocketMessage
(
callback
):
void
request
(
options
):
void
}
class
DebugPlatform
implements
Platform
{
async
getUserInfo
()
{
return
{
nickName
:
"username"
}
}
async
login
()
{
}
showToast
(
title
){
}
connectSocket
(
options
){
}
onSocketOpen
(
callback
){
}
onSocketClose
(
callback
){
}
onSocketMessage
(
options
){
}
onSocketError
(
callback
){
}
sendSocketMessage
(
callback
){
}
request
(){
}
}
...
...
fe/src/scenes/GameScene.ts
View file @
2aee812d
class
GameScene
extends
egret
.
Sprite
{
private
controller
public
constructor
()
{
super
();
this
.
init
()
}
// 初始化(给开始按钮绑定点击事件)
private
init
()
{
// put display object to this scene
this
.
controller
=
new
Controller
()
this
.
addChild
(
this
.
controller
)
}
public
release
()
{
...
...
fe/template/runtime/native_require.js
View file @
2aee812d
...
...
@@ -31,7 +31,19 @@ egret_native.egretStart = function () {
//以下为自动修改,请勿修改
//The following is automatically modified, please do not modify
//----auto option start----
//----auto option end----
entryClassName
:
"Main"
,
frameRate
:
30
,
scaleMode
:
"fixedWidth"
,
contentWidth
:
640
,
contentHeight
:
1136
,
showPaintRect
:
false
,
showFPS
:
false
,
fpsStyles
:
"x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9"
,
showLog
:
false
,
logFilter
:
""
,
maxTouches
:
2
,
textureScaleFactor
:
1
//----auto option end----
};
egret
.
native
.
NativePlayer
.
option
=
option
;
...
...
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