Audio looping, proper sizing for fullscreen on images
This commit is contained in:
parent
b5da68a56e
commit
d05736773b
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
docs/
|
docs/
|
||||||
examples/*/dist/
|
examples/*/dist/
|
||||||
|
browse.VC.db
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "momentumengine",
|
"name": "momentumengine",
|
||||||
"version": "0.9.0",
|
"version": "0.10.0",
|
||||||
"description": "An ES6 game and animation engine.",
|
"description": "An ES6 game and animation engine.",
|
||||||
"main": "src/es6.js",
|
"main": "src/es6.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
class Audio {
|
class AudioTrack {
|
||||||
|
|
||||||
|
|
||||||
constructor (src) {
|
constructor (src) {
|
||||||
|
|
||||||
this._loaded = false; // Default is true, set it to false until the audio has loaded
|
this._loaded = false; // Default is true, set it to false until the audio has loaded
|
||||||
this._error = false; // If the audio fails to load, this will contain the reason
|
this._error = false; // If the audio fails to load, this will contain the reason
|
||||||
|
this._loop = false;
|
||||||
|
|
||||||
this._audioObj = new Audio();
|
this._audioObj = new Audio();
|
||||||
|
|
||||||
this._audioObj.addEventListener("loadeddata", () => {
|
this._audioObj.addEventListener("loadeddata", () => {
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
this._error = false;
|
this._error = false;
|
||||||
|
|
||||||
|
this._audioObj.addEventListener("ended", () => {
|
||||||
|
if (this._loop) {
|
||||||
|
this._audioObj.currentTime = 0;
|
||||||
|
this._audioObj.play();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this._audioObj.addEventListener("error", (err) => {
|
this._audioObj.addEventListener("error", (err) => {
|
||||||
@ -25,6 +34,16 @@ class Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
get loop () {
|
||||||
|
return this._loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
set loop (shouldLoop) {
|
||||||
|
return this._loop = shouldLoop;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
play () {
|
play () {
|
||||||
if (this._loaded) {
|
if (this._loaded) {
|
||||||
return this._audioObj.play();
|
return this._audioObj.play();
|
||||||
@ -65,4 +84,4 @@ class Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default Audio;
|
export default AudioTrack;
|
@ -58,10 +58,10 @@ class Sprite extends Entity {
|
|||||||
this._imagePos.y,
|
this._imagePos.y,
|
||||||
this._imageSize.x || subWidth,
|
this._imageSize.x || subWidth,
|
||||||
this._imageSize.y || subHeight,
|
this._imageSize.y || subHeight,
|
||||||
this.relativeLeft,
|
this._scaleForLeft(this.relativeLeft),
|
||||||
this.relativeTop,
|
this._scaleForTop(this.relativeTop),
|
||||||
this.width || subWidth,
|
this._scaleForWidth(this.width || subWidth),
|
||||||
this.height || subHeight
|
this._scaleForHeight(this.height || subHeight)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -11,7 +11,7 @@ import Path from "./classes/path.js";
|
|||||||
import Color from "./classes/color.js";
|
import Color from "./classes/color.js";
|
||||||
import Text from "./classes/text.js";
|
import Text from "./classes/text.js";
|
||||||
import Font from "./classes/font.js";
|
import Font from "./classes/font.js";
|
||||||
import Audio from "./classes/audio.js";
|
import AudioTrack from "./classes/audio.js";
|
||||||
import ImageLoader from "./classes/imageloader.js";
|
import ImageLoader from "./classes/imageloader.js";
|
||||||
|
|
||||||
import {KeyConsts} from "./classes/keyboardinput.js";
|
import {KeyConsts} from "./classes/keyboardinput.js";
|
||||||
@ -29,7 +29,7 @@ const Classes = {
|
|||||||
Color,
|
Color,
|
||||||
Text,
|
Text,
|
||||||
Font,
|
Font,
|
||||||
Audio,
|
AudioTrack,
|
||||||
ImageLoader
|
ImageLoader
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import Path from "./classes/path.js";
|
|||||||
import Color from "./classes/color.js";
|
import Color from "./classes/color.js";
|
||||||
import Text from "./classes/text.js";
|
import Text from "./classes/text.js";
|
||||||
import Font from "./classes/font.js";
|
import Font from "./classes/font.js";
|
||||||
import Audio from "./classes/audio.js";
|
import AudioTrack from "./classes/audio.js";
|
||||||
import ImageLoader from "./classes/imageloader.js";
|
import ImageLoader from "./classes/imageloader.js";
|
||||||
|
|
||||||
import {KeyConsts} from "./classes/keyboardinput.js";
|
import {KeyConsts} from "./classes/keyboardinput.js";
|
||||||
@ -29,7 +29,7 @@ const Classes = {
|
|||||||
Color,
|
Color,
|
||||||
Text,
|
Text,
|
||||||
Font,
|
Font,
|
||||||
Audio,
|
AudioTrack,
|
||||||
ImageLoader
|
ImageLoader
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user