Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
NJ_game_select
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
NJ_game_select
Commits
301c7281
Commit
301c7281
authored
May 24, 2022
by
liujiangnan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://vcs.ireadabc.com/template/NJ_game_select
parents
c199c49c
1e11767b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
184 deletions
+143
-184
NJ_game_select.ts
assets/NJ_game_select/scene/NJ_game_select.ts
+26
-179
defaultData.ts
assets/NJ_game_select/script/defaultData.ts
+18
-4
util.ts
assets/NJ_game_select/script/util.ts
+99
-1
No files found.
assets/NJ_game_select/scene/NJ_game_select.ts
View file @
301c7281
import
{
asyncDelay
,
onHomeworkFinish
}
from
"
../script/util
"
;
import
{
async
CallNetworkApiGet
,
async
Delay
,
onHomeworkFinish
}
from
"
../script/util
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -6,190 +6,37 @@ const { ccclass, property } = cc._decorator;
@
ccclass
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
addPreloadImage
()
{
// TODO 根据自己的配置预加载图片资源
this
.
_imageResList
.
push
({
url
:
this
.
data
.
pic_url
});
this
.
_imageResList
.
push
({
url
:
this
.
data
.
pic_url_2
});
}
addPreloadAudio
()
{
// TODO 根据自己的配置预加载音频资源
this
.
_audioResList
.
push
({
url
:
this
.
data
.
audio_url
});
}
addPreloadAnima
()
{
}
onLoadEnd
()
{
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this
.
initData
();
this
.
initView
();
this
.
initListener
();
}
_cantouch
=
null
;
initData
()
{
// 所有全局变量 默认都是null
this
.
_cantouch
=
true
;
}
initView
()
{
this
.
initBg
();
this
.
initPic
();
this
.
initBtn
();
this
.
initIcon
();
}
initBg
()
{
const
bgNode
=
cc
.
find
(
'
Canvas/bg
'
);
bgNode
.
scale
=
this
.
_mapScaleMax
;
}
pic1
=
null
;
pic2
=
null
;
initPic
()
{
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
maxW
=
canvas
.
width
*
0.7
;
this
.
getSprNodeByUrl
(
this
.
data
.
pic_url
,
(
sprNode
)
=>
{
const
picNode1
=
sprNode
;
picNode1
.
scale
=
maxW
/
picNode1
.
width
;
picNode1
.
baseX
=
picNode1
.
x
;
canvas
.
addChild
(
picNode1
);
this
.
pic1
=
picNode1
;
const
labelNode
=
new
cc
.
Node
();
labelNode
.
color
=
cc
.
Color
.
YELLOW
;
const
label
=
labelNode
.
addComponent
(
cc
.
Label
);
label
.
string
=
this
.
data
.
text
;
label
.
fontSize
=
60
;
label
.
lineHeight
=
60
;
label
.
font
=
cc
.
find
(
'
Canvas/res/font/BRLNSDB
'
).
getComponent
(
'
cc.Label
'
).
font
;
picNode1
.
addChild
(
labelNode
);
});
this
.
getSprNodeByUrl
(
this
.
data
.
pic_url_2
,
(
sprNode
)
=>
{
const
picNode2
=
sprNode
;
picNode2
.
scale
=
maxW
/
picNode2
.
width
;
canvas
.
addChild
(
picNode2
);
picNode2
.
x
=
canvas
.
width
;
picNode2
.
baseX
=
picNode2
.
x
;
this
.
pic2
=
picNode2
;
const
labelNode
=
new
cc
.
Node
();
const
label
=
labelNode
.
addComponent
(
cc
.
RichText
);
const
size
=
60
label
.
font
=
cc
.
find
(
'
Canvas/res/font/BRLNSDB
'
).
getComponent
(
cc
.
Label
).
font
;
label
.
string
=
`<outline color=#751e00 width=4><size=
${
size
}
><color=#ffffff>
${
this
.
data
.
text
}
</color></size></outline>`
label
.
lineHeight
=
size
;
picNode2
.
addChild
(
labelNode
);
});
addPreloadImage
()
{
// this._imageResList.push({ url: this.data.pic_url });
}
}
initIcon
()
{
const
iconNode
=
this
.
getSprNode
(
'
icon
'
);
iconNode
.
zIndex
=
5
;
iconNode
.
anchorX
=
1
;
iconNode
.
anchorY
=
1
;
iconNode
.
parent
=
cc
.
find
(
'
Canvas
'
);
iconNode
.
x
=
iconNode
.
parent
.
width
/
2
-
10
;
iconNode
.
y
=
iconNode
.
parent
.
height
/
2
-
10
;
async
onLoadEnd
()
{
await
this
.
initData
();
this
.
initView
();
this
.
initListener
();
}
iconNode
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
this
.
playAudioByUrl
(
this
.
data
.
audio_url
);
})
async
initData
()
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
!
middleLayer
)
{
return
;
}
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
const
folderId
=
middleLayerComponent
.
getData
();
console
.
log
(
'
folderId =
'
+
folderId
);
curPage
=
null
;
initBtn
()
{
this
.
curPage
=
0
;
const
bottomPart
=
cc
.
find
(
'
Canvas/bottomPart
'
);
bottomPart
.
zIndex
=
5
;
// 提高层级
bottomPart
.
x
=
bottomPart
.
parent
.
width
/
2
;
bottomPart
.
y
=
-
bottomPart
.
parent
.
height
/
2
;
const
leftBtnNode
=
bottomPart
.
getChildByName
(
'
btn_left
'
);
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode
.
on
(
'
click
'
,
()
=>
{
if
(
!
this
.
_cantouch
)
{
return
;
}
if
(
this
.
curPage
==
0
)
{
return
;
}
this
.
curPage
=
0
this
.
leftMove
();
const
resStr
=
await
asyncCallNetworkApiGet
(
'
/api/syllabus/v1/list
'
,
{
pid
:
folderId
});
console
.
log
(
'
resStr =
'
+
resStr
);
const
res
=
JSON
.
parse
(
resStr
);
}
this
.
playLocalAudio
(
'
btn
'
);
})
initView
()
{
const
rightBtnNode
=
bottomPart
.
getChildByName
(
'
btn_right
'
);
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode
.
on
(
'
click
'
,
()
=>
{
if
(
!
this
.
_cantouch
)
{
return
;
}
if
(
this
.
curPage
==
1
)
{
return
;
}
}
this
.
curPage
=
1
this
.
rightMove
();
initListener
()
{
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish
();
this
.
playLocalAudio
(
'
btn
'
);
})
}
leftMove
()
{
this
.
_cantouch
=
false
;
const
len
=
this
.
pic1
.
parent
.
width
;
cc
.
tween
(
this
.
pic1
)
.
to
(
1
,
{
x
:
this
.
pic1
.
baseX
},
{
easing
:
'
cubicInOut
'
})
.
start
();
cc
.
tween
(
this
.
pic2
)
.
to
(
1
,
{
x
:
this
.
pic2
.
baseX
},
{
easing
:
'
cubicInOut
'
})
.
call
(()
=>
{
this
.
_cantouch
=
true
;
})
.
start
();
}
rightMove
()
{
this
.
_cantouch
=
false
;
const
len
=
this
.
pic1
.
parent
.
width
;
cc
.
tween
(
this
.
pic1
)
.
to
(
1
,
{
x
:
this
.
pic1
.
baseX
-
len
},
{
easing
:
'
cubicInOut
'
})
.
start
();
cc
.
tween
(
this
.
pic2
)
.
to
(
1
,
{
x
:
this
.
pic2
.
baseX
-
len
},
{
easing
:
'
cubicInOut
'
})
.
call
(()
=>
{
this
.
_cantouch
=
true
;
})
.
start
();
}
// update (dt) {},
initListener
()
{
}
playLocalAudio
(
audioName
)
{
const
audio
=
cc
.
find
(
`Canvas/res/audio/
${
audioName
}
`
).
getComponent
(
cc
.
AudioSource
);
return
new
Promise
((
resolve
,
reject
)
=>
{
const
id
=
cc
.
audioEngine
.
playEffect
(
audio
.
clip
,
false
);
cc
.
audioEngine
.
setFinishCallback
(
id
,
()
=>
{
resolve
(
id
);
});
})
}
}
}
assets/NJ_game_select/script/defaultData.ts
View file @
301c7281
export
const
defaultData
=
{
"
pic_url
"
:
"
http://staging-teach.cdn.ireadabc.com/ed94332a503c31e0908bd4c6923a2665.png
"
,
"
pic_url_2
"
:
"
http://staging-teach.cdn.ireadabc.com/5fb60317ade0195d35ad8034d5370a7f.png
"
,
"
text
"
:
"
This is a test label.
"
,
"
audio_url
"
:
"
http://staging-teach.cdn.ireadabc.com/f47f1d7b5c160fe1c59500d180346240.mp3
"
bookPages
:
[{
pageIdx
:
1
,
// 第几页
startAudio
:
'
http://xxxx.mp3
'
,
// 页码引导音频
startBg
:
'
http://xxxx.jpg
'
,
// 页码背景图片
scanImg
:
'
http://xxxx.jpg
'
,
// 页码扫描图片
bookDataInfo
:
{
bgItem
:
{
guidAudio
:
'
http://xxxx.mp3
'
,
// 热区引导音频
guidBg
:
'
http://xxxx.jpg
'
,
// 热区背景图片
},
hotZoneArr
:
[{
// 数组顺序
rect
:
{
x
:
0
,
y
:
0
,
width
:
100
,
height
:
100
},
},
{
// 数组顺序
rect
:
{
x
:
0
,
y
:
0
,
width
:
100
,
height
:
100
},
}]
}
}]
}
\ No newline at end of file
assets/NJ_game_select/script/util.ts
View file @
301c7281
...
...
@@ -421,4 +421,102 @@ export function onHomeworkFinish() {
}
else
{
console
.
log
(
'
onHomeworkFinish
'
);
}
}
\ No newline at end of file
}
export
function
asyncCallNetworkApiGet
(
apiName
,
data
):
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiGet
(
apiName
,
data
,
(
res
=>
{
resolve
(
res
);
}));
});
}
export
function
asyncCallNetworkApiPost
(
uri
,
data
):
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiPost
(
uri
,
data
,
(
res
)
=>
{
resolve
(
res
);
});
});
}
export
function
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiPost
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
baseUrl
}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
)
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
}
export
function
callNetworkApiGet
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiGet
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
}
export
function
jumpToBundle
(
bundleName
:
string
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineBundle
(
bundleName
);
}
else
{
console
.
log
(
'
jump to bundle:
'
+
bundleName
);
}
}
export
function
jumpToCourseWare
(
courseWareId
:
number
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineCourseWare
(
courseWareId
);
}
else
{
console
.
log
(
'
jump to CourseWare:
'
+
courseWareId
);
}
}
export
function
buttonOnClick
(
button
:
cc
.
Node
,
callback
:
Function
,
scale
=
1.1
)
{
button
.
on
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
})
.
to
(
0.1
,
{
scale
:
1.0
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
});
}
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