forked from flame-engine/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Update flame_audio to AP 1.0.0 (flame-engine#1724)
- Loading branch information
1 parent
a0a0509
commit 7121b19
Showing
16 changed files
with
251 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# AudioPool | ||
|
||
An AudioPool is a provider of AudioPlayers that are pre-loaded with | ||
local assets to minimize delays. | ||
|
||
A single AudioPool always plays the same sound, usually a quick sound | ||
effect, like a laser shooting from your ship or a jump sound for your | ||
platformer. | ||
|
||
The advantage of using Audio Pool is that by configuring a minimum | ||
(starting) size, and a maximum size, the pool will create and preload | ||
some players, and allow them to be re-used many times. | ||
|
||
You can use the helper method `FlameAudio.createPool` to create AudioPool | ||
instances using the same global `FlameAudio.audioCache`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
General audio <audio.md> | ||
Background music <bgm.md> | ||
AudioPool <audio_pool.md> | ||
``` |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:dashbook/dashbook.dart'; | ||
import 'package:examples/commons/commons.dart'; | ||
import 'package:examples/stories/bridge_libraries/audio/basic_audio_example.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
void addAudioStories(Dashbook dashbook) { | ||
dashbook.storiesOf('Audio').add( | ||
'Basic Audio', | ||
(_) => GameWidget(game: BasicAudioExample()), | ||
codeLink: baseLink('audio/basic_audio_example.dart'), | ||
info: BasicAudioExample.description, | ||
); | ||
} |
84 changes: 84 additions & 0 deletions
84
examples/lib/stories/bridge_libraries/audio/basic_audio_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/extensions.dart'; | ||
import 'package:flame/game.dart'; | ||
import 'package:flame/input.dart'; | ||
import 'package:flame/palette.dart'; | ||
import 'package:flame_audio/audio_pool.dart'; | ||
import 'package:flame_audio/flame_audio.dart'; | ||
import 'package:flutter/painting.dart'; | ||
|
||
class BasicAudioExample extends FlameGame with TapDetector { | ||
static const String description = ''' | ||
This example showcases the most basic Flame Audio functionalities. | ||
1. Use the static FlameAudio class to easily fire a sfx using the default | ||
configs for the button tap. | ||
2. Uses a custom AudioPool for extremely efficient audio loading and pooling | ||
for tapping elsewhere. | ||
3. Uses the Bgm utility for background music. | ||
'''; | ||
|
||
static Paint black = BasicPalette.black.paint(); | ||
static Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint(); | ||
static TextPaint text = TextPaint( | ||
style: TextStyle(color: BasicPalette.white.color), | ||
); | ||
|
||
late AudioPool pool; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
pool = await FlameAudio.createPool( | ||
'sfx/fire_2.mp3', | ||
minPlayers: 3, | ||
maxPlayers: 4, | ||
); | ||
startBgmMusic(); | ||
} | ||
|
||
Rect get button => Rect.fromLTWH(20, size.y - 300, size.x - 40, 200); | ||
|
||
void startBgmMusic() { | ||
FlameAudio.bgm.initialize(); | ||
FlameAudio.bgm.play('music/bg_music.ogg'); | ||
} | ||
|
||
void fireOne() { | ||
FlameAudio.play('sfx/fire_1.mp3'); | ||
} | ||
|
||
void fireTwo() { | ||
pool.start(); | ||
} | ||
|
||
@override | ||
void render(Canvas canvas) { | ||
super.render(canvas); | ||
canvas.drawRect(size.toRect(), black); | ||
|
||
text.render( | ||
canvas, | ||
'(click anywhere for 1)', | ||
Vector2(size.x / 2, 200), | ||
anchor: Anchor.topCenter, | ||
); | ||
|
||
canvas.drawRect(button, gray); | ||
|
||
text.render( | ||
canvas, | ||
'click here for 2', | ||
Vector2(size.x / 2, size.y - 200), | ||
anchor: Anchor.bottomCenter, | ||
); | ||
} | ||
|
||
@override | ||
void onTapDown(TapDownInfo details) { | ||
if (button.containsPoint(details.eventPosition.game)) { | ||
fireTwo(); | ||
} else { | ||
fireOne(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.