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
a64360eb
Commit
a64360eb
authored
May 05, 2018
by
Mike Zhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加音效管理
parent
9bf5c6d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
Main.ts
fe/src/Main.ts
+2
-0
SoundManager.ts
fe/src/SoundManager.ts
+45
-0
No files found.
fe/src/Main.ts
View file @
a64360eb
...
...
@@ -161,6 +161,8 @@ class Main extends egret.DisplayObjectContainer {
*/
private
createGameScene
()
{
this
.
addChild
(
SceneManager
.
getInstance
());
// SoundManager.getInstance().play({soundName: 'bgm_mp3', loops: -1})
// SoundManager.getInstance().playCatched(1)
}
/**
...
...
fe/src/SoundManager.ts
0 → 100644
View file @
a64360eb
class
SoundManager
{
private
static
instance
:
SoundManager
;
private
sounds
:
any
public
constructor
()
{
this
.
init
()
}
private
init
()
{
this
.
sounds
=
{}
const
soundNames
=
[
'catched_0_mp3'
,
'catched_1_mp3'
,
'catched_2_mp3'
,
'flirt_mp3'
,
'bgm_mp3'
,
]
soundNames
.
forEach
(
soundName
=>
{
this
.
sounds
[
soundName
]
=
RES
.
getRes
(
soundName
)
})
}
// 实例化单例获取方法
public
static
getInstance
():
SoundManager
{
if
(
!
SoundManager
.
instance
)
{
SoundManager
.
instance
=
new
SoundManager
();
}
return
SoundManager
.
instance
;
}
public
play
({
soundName
,
startTime
=
0
,
loops
=
1
})
{
this
.
sounds
[
soundName
].
play
(
startTime
,
loops
)
}
// 随机播放被抓音频
public
playCatched
(
num
?)
{
const
soundName
=
[
'catched_0_mp3'
,
'catched_2_mp3'
,
][
num
||
this
.
rnd
(
0
,
1
)]
this
.
play
({
soundName
})
}
rnd
(
start
,
end
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
end
-
start
)
+
start
)
}
}
\ No newline at end of file
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