@mep.tech/instant v2.9.8
MEPInstant
Top level namespace for the Instant Games SDK.
initializeAsync()
Initializes the SDK library. This should be called before any other SDK functions.
Examples
MEPInstant.initializeAsync().then(function() {
// Many properties will be null until the initialization completes.
// This is a good place to fetch them:
var platform = MEPInstant.getPlatform(); // 'IOS'
var sdkVersion = MEPInstant.getSDKVersion(); // '2.0'
var playerID = MEPInstant.getPlayerID();
});Returns Promise\<void> that resolves when the SDK is ready to use.
getSDKVersion()
The string representation of this SDK version.
Examples
var sdkVersion = MEPInstant.getSDKVersion(); // '2.0'Returns string The SDK version.
getPlatform()
The platform on which the game is currently running.
Examples
var platform = MEPInstant.getPlatform(); // 'IOS'Returns string The platform.
getPlayerId()
Get the id of the player.
Examples
var platform = getPlayerId(); // '123'Returns string The player id.
startGameAsync()
Start the game initialization flow.
Examples
MEPInstant.startGameAsync().then(function(song: Song) {
myGame.start(song);
});Returns Promise\<Song> that resolves when game is loaded and data is fulfilled.
getNotesAsync()
Read notes data from the level file.
Parameters
levelUrlstring The link to level file.
Examples
MEPInstant.getNotesAsync().then(function(notes: Note[]) {
myGame.createObstacles(notes);
});Returns Promise\<Note[]> that resolves when the notes data is fetched.
onPause()
Set a callback to be fired when a pause event is triggered.
Parameters
funcFunction A function to call when a pause event occurs.
Examples
MEPInstant.onPause(function() {
console.log('Pause event was triggered!');
pauseGameplay();
})Returns void
onResume()
Set a callback to be fired when a resume event is triggered.
Parameters
funcFunction A function to call when a resume event occurs.
Examples
MEPInstant.onResume(function() {
console.log('Resume event was triggered!');
resumeGameplay();
})Returns void
showReviveConfirmation()
Show a revise confirmation dialog to allow user to choose whether continue or end game.
Parameters
onYesAnswerFunction A function to call when user has chosen continue.onNoAnswerFunction A function to call when user has chosen stop.
Examples
MEPInstant.showReviveConfirmation(
function() {
console.log('Continue is chose!');
continueGameplay();
},
function() {
console.log('Stop is chose!');
stopGameplay();
})Returns void
endGame()
Indicates that the game has finished.
Parameters
resultResult The playing section result.
Examples
MEPInstant.endGame({ score: 23, star: 3, crown: 1, loop: 2, notes: 100, revise: 0, 1.4});Returns void
createMusicPlayer()
Create music player to control music playback.
Parameters
optionsMusicPlayerOptions The music player options.
Examples
var player = createMusicPlayer({
src: mp3Url,
onLoad: function() {
loadLevel()
}
});Returns MusicPlayer to control music playback.
MusicPlayer
Music player that should be used to control music playback. In our game we use MusicPlayer to play mp3.
play()
Play music or resume previous playback.
Examples
player.play();Returns void
pause()
Pause playback and save current position.
Examples
player.pause();Returns void
resume()
Resume previous playback.
Examples
player.resume();Returns void
stop()
Stop playback and reset to start.
Examples
player.stop();Returns void
getDuration()
Get the duration.
Examples
var duration = player.getDuration(); // 120Returns number the duration in second.
setCurrentTime()
Set the current position of a sound.
Parameters
secnumber The position in second.
Examples
player.setCurrentTime(30);Returns number the duration in second.
getCurrentTime()
Get the current position of a playback.
Examples
var currentTime = player.getCurrentTime(); // 90Returns number the current position in second.
setVolume()
Set the volume for sound.
Parameters
volumenumber Volume from 0.0 to 1.0.
Examples
player.setVolume(0.9);Returns void
getVolume()
Get the volume.
Examples
var volume = player.getVolume(); // 0.6Returns number the volume.
isPlaying()
Check if a music is currently playing or not.
Examples
if (!player.isPlaying()) {
player.play()
}Returns boolean True if playing and false if not.
getState()
Returns the current loaded state.
Examples
var state = player.getState() // "loaded"Returns string One of "unloaded", "loading", "loaded".
Song
Represents a song data for MEPInstant.startGameAsync.
Type: Object
Properties
idstring Song's id.titlestring Song's title.artiststring Artist's name.durationnumber Duration in second.mp3Urlstring Link to the mp3.levelUrlstring Link to level.
Note
Represents a note data for MEPInstant.getNotesAsync.
Type: Object
Properties
namestring Name of note.timenumber Time in seconds when the note is appeared.durationnumber Duration of note in seconds.
Result
Represents a result data for MEPInstant.endGame.
Type: Object
Properties
scorenumber The score.starnumber The star.crownnumber The crown. Earn by playing endless mode.notesnumber The number of notes have been hit.loopnumber The loop count. Once song is over then loop += 1.revisenumber The revise count.percentnumber The percentage of current song. e.g. 0.8.
MusicPlayerOptions
Represents option to create an MusicPlayer.
Type: Object
Properties
srcstring The sources to the track(s) to be loaded for the sound (URLs or base64 data URIs).loopboolean Set to true to automatically loop the sound forever. defaultfalse.autoplayboolean Set to true to automatically start playback when sound is loaded. defaultfalse.ratenumber The rate of playback. 0.5 to 4.0, with 1.0 being normal speed. default1.0onLoadFunction Fires when the sound is loaded.onPlayFunction Fires when the sound begins playing.onSeekFunction Fires when the sound has been seeked.onPauseFunction Fires when the sound has been paused.onStopFunction Fires when the sound has been stopped.onEndFunction Fires when the sound finishes playing (if it is looping, it'll fire at the end of each loop).
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago