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/
|
||||
docs/
|
||||
examples/*/dist/
|
||||
browse.VC.db
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "momentumengine",
|
||||
"version": "0.9.0",
|
||||
"version": "0.10.0",
|
||||
"description": "An ES6 game and animation engine.",
|
||||
"main": "src/es6.js",
|
||||
"repository": {
|
||||
|
@ -1,18 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
class Audio {
|
||||
class AudioTrack {
|
||||
|
||||
|
||||
constructor (src) {
|
||||
|
||||
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._loop = false;
|
||||
|
||||
this._audioObj = new Audio();
|
||||
|
||||
this._audioObj.addEventListener("loadeddata", () => {
|
||||
this._loaded = true;
|
||||
this._error = false;
|
||||
|
||||
this._audioObj.addEventListener("ended", () => {
|
||||
if (this._loop) {
|
||||
this._audioObj.currentTime = 0;
|
||||
this._audioObj.play();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
this._audioObj.addEventListener("error", (err) => {
|
||||
@ -25,6 +34,16 @@ class Audio {
|
||||
}
|
||||
|
||||
|
||||
get loop () {
|
||||
return this._loop;
|
||||
}
|
||||
|
||||
|
||||
set loop (shouldLoop) {
|
||||
return this._loop = shouldLoop;
|
||||
}
|
||||
|
||||
|
||||
play () {
|
||||
if (this._loaded) {
|
||||
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._imageSize.x || subWidth,
|
||||
this._imageSize.y || subHeight,
|
||||
this.relativeLeft,
|
||||
this.relativeTop,
|
||||
this.width || subWidth,
|
||||
this.height || subHeight
|
||||
this._scaleForLeft(this.relativeLeft),
|
||||
this._scaleForTop(this.relativeTop),
|
||||
this._scaleForWidth(this.width || subWidth),
|
||||
this._scaleForHeight(this.height || subHeight)
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -11,7 +11,7 @@ import Path from "./classes/path.js";
|
||||
import Color from "./classes/color.js";
|
||||
import Text from "./classes/text.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 {KeyConsts} from "./classes/keyboardinput.js";
|
||||
@ -29,7 +29,7 @@ const Classes = {
|
||||
Color,
|
||||
Text,
|
||||
Font,
|
||||
Audio,
|
||||
AudioTrack,
|
||||
ImageLoader
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,7 @@ import Path from "./classes/path.js";
|
||||
import Color from "./classes/color.js";
|
||||
import Text from "./classes/text.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 {KeyConsts} from "./classes/keyboardinput.js";
|
||||
@ -29,7 +29,7 @@ const Classes = {
|
||||
Color,
|
||||
Text,
|
||||
Font,
|
||||
Audio,
|
||||
AudioTrack,
|
||||
ImageLoader
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user