diff --git a/.gitignore b/.gitignore index c6653c4..e0afdae 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ dist/ docs/ examples/*/dist/ +browse.VC.db diff --git a/package.json b/package.json index df2f246..f5534f2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/classes/audio.js b/src/classes/audio.js index 56869f0..1c818d4 100644 --- a/src/classes/audio.js +++ b/src/classes/audio.js @@ -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; \ No newline at end of file +export default AudioTrack; \ No newline at end of file diff --git a/src/classes/sprite.js b/src/classes/sprite.js index 7e7c6ac..ae6bd5c 100644 --- a/src/classes/sprite.js +++ b/src/classes/sprite.js @@ -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; diff --git a/src/es5.js b/src/es5.js index 7451c76..d16cf9b 100644 --- a/src/es5.js +++ b/src/es5.js @@ -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 }; diff --git a/src/es6.js b/src/es6.js index 5458dff..01c8694 100644 --- a/src/es6.js +++ b/src/es6.js @@ -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 };