mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Added in the final DOM level functions.
This commit is contained in:
parent
970dea20f5
commit
36ca61dddb
9 changed files with 127 additions and 4 deletions
|
@ -66,6 +66,10 @@ function Config (config)
|
|||
|
||||
this.forceSetTimeOut = getValue(config, 'forceSetTimeOut', false);
|
||||
|
||||
this.transparent = getValue(config, 'transparent', false);
|
||||
|
||||
this.pixelArt = getValue(config, 'pixelArt', false);
|
||||
|
||||
}
|
||||
|
||||
Config.prototype.constructor = Config;
|
||||
|
|
|
@ -9,6 +9,7 @@ var CHECKSUM = require('../checksum');
|
|||
var Config = require('./Config');
|
||||
var DebugHeader = require('./DebugHeader');
|
||||
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
|
||||
var DOMContentLoaded = require('../dom/DOMContentLoaded');
|
||||
|
||||
var Game = function (config)
|
||||
{
|
||||
|
@ -69,9 +70,7 @@ var Game = function (config)
|
|||
|
||||
// this.device.whenReady(this.boot, this);
|
||||
|
||||
DebugHeader(this);
|
||||
|
||||
console.log(CHECKSUM.build);
|
||||
DOMContentLoaded(this.boot.bind(this));
|
||||
|
||||
};
|
||||
|
||||
|
@ -79,6 +78,17 @@ Game.prototype.constructor = Game;
|
|||
|
||||
Game.prototype = {
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
DebugHeader(this);
|
||||
|
||||
console.log(CHECKSUM.build);
|
||||
|
||||
// Add in ability to specify pre-init and post-init callbacks in the config
|
||||
|
||||
this.raf.start();
|
||||
},
|
||||
|
||||
update: function (timestamp)
|
||||
{
|
||||
// console.log(timestamp);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = {
|
||||
|
||||
// Doing this makes it available under Phaser.Game
|
||||
Game: require('./Game')
|
||||
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '9d525b60-b2af-11e6-8aab-1f6b9d8fd351'
|
||||
build: '8fd01380-b2b2-11e6-b621-1f12dc04eec3'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
8
v3/src/dom/AddEventListener.js
Normal file
8
v3/src/dom/AddEventListener.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
function AddEventListener (target, event, listener, useCapture)
|
||||
{
|
||||
if (useCapture === undefined) { useCapture = false; }
|
||||
|
||||
target.addEventListener(event, listener, useCapture);
|
||||
}
|
||||
|
||||
module.exports = AddEventListener;
|
38
v3/src/dom/AddToDOM.js
Normal file
38
v3/src/dom/AddToDOM.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
function AddToDOM (element, parent, overflowHidden)
|
||||
{
|
||||
if (overflowHidden === undefined) { overflowHidden = true; }
|
||||
|
||||
var target;
|
||||
|
||||
if (parent)
|
||||
{
|
||||
if (typeof parent === 'string')
|
||||
{
|
||||
// Hopefully an element ID
|
||||
target = document.getElementById(parent);
|
||||
}
|
||||
else if (typeof parent === 'object' && parent.nodeType === 1)
|
||||
{
|
||||
// Quick test for a HTMLelement
|
||||
target = parent;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback, covers an invalid ID and a non HTMLelement object
|
||||
if (!target)
|
||||
{
|
||||
target = document.body;
|
||||
}
|
||||
|
||||
if (overflowHidden && target.style)
|
||||
{
|
||||
target.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
target.appendChild(element);
|
||||
|
||||
return element;
|
||||
|
||||
}
|
||||
|
||||
module.exports = AddToDOM;
|
47
v3/src/dom/DOMContentLoaded.js
Normal file
47
v3/src/dom/DOMContentLoaded.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var isBooted = false;
|
||||
|
||||
function DOMContentLoaded (callback)
|
||||
{
|
||||
if (isBooted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
||||
{
|
||||
isBooted = true;
|
||||
|
||||
callback();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var check = function ()
|
||||
{
|
||||
isBooted = true;
|
||||
|
||||
document.removeEventListener('deviceready', check, true);
|
||||
document.removeEventListener('DOMContentLoaded', check, true);
|
||||
window.removeEventListener('load', check, true);
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
if (!document.body)
|
||||
{
|
||||
window.setTimeout(check, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.addEventListener('DOMContentLoaded', check, true);
|
||||
window.addEventListener('load', check, true);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DOMContentLoaded;
|
6
v3/src/dom/RemoveEventListener.js
Normal file
6
v3/src/dom/RemoveEventListener.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
function RemoveEventListener (target, event, listener)
|
||||
{
|
||||
target.removeEventListener(event, listener);
|
||||
}
|
||||
|
||||
module.exports = RemoveEventListener;
|
9
v3/src/dom/RemoveFromDOM.js
Normal file
9
v3/src/dom/RemoveFromDOM.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
function RemoveFromDOM (element)
|
||||
{
|
||||
if (element.parentNode)
|
||||
{
|
||||
element.parentNode.removeChild(element);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RemoveFromDOM;
|
Loading…
Reference in a new issue