New Timer class and scale event updates.

This commit is contained in:
photonstorm 2013-11-24 11:04:58 +00:00
parent 7d7aa795e7
commit 155c863d69
12 changed files with 344 additions and 151 deletions

View file

@ -109,6 +109,7 @@ module.exports = function (grunt) {
'src/tween/Tween.js',
'src/tween/Easing.js',
'src/time/Time.js',
'src/time/Timer.js',
'src/animation/AnimationManager.js',
'src/animation/Animation.js',
'src/animation/Frame.js',

View file

@ -60,6 +60,8 @@ Version 1.1.3 - in build
* New: Added Group.sort. You can now sort the Group based on any given numeric property (x, y, health), finally you can do depth-sorting :) Example created to show.
* New: Enhanced renderTexture so it can accept a Phaser.Group object and improved documentation and examples.
* New: Device.littleEndian boolean added. Only safe to use if the browser supports TypedArrays (which IE9 doesn't, but nearly all others do)
* New: You can now call game.sound.play() and simply pass it a key. The sound will play if the audio system is unlocked and optionally destroy itself on complete.
* New: Mouse.capture is a boolean. If set to true then DOM mouse events will have event.preventDefault() applied, if false they will propogate fully.
* Fixed: Lots of fixes to the TypeScript definitions file (many thanks gltovar)
* Fixed: Tilemap commands use specified layer when one given (thanks Izzimach)
@ -79,7 +81,7 @@ Version 1.1.3 - in build
* Updated: Tided up the Graphics object (thanks BorisKozo)
* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function.
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
* Updated: Lots of documentation tweaks across various files such as Pointer and Color.
* Updated: Lots of documentation tweaks across various files such as Pointer, Sound and Color.
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)

View file

@ -1,150 +1,159 @@
<?php
// All JS files in build order.
// Much easier for debugging re: line numbers
?>
<script src="../src/Intro.js"></script>
<script src="../src/pixi/Pixi.js"></script>
<script src="../src/Phaser.js"></script>
<script src="../src/utils/Utils.js"></script>
if (!isset($path))
{
$path = '..';
}
<script src="../src/pixi/core/Matrix.js"></script>
<script src="../src/pixi/core/Point.js"></script>
<script src="../src/pixi/core/Rectangle.js"></script>
<script src="../src/pixi/core/Polygon.js"></script>
echo <<<EOL
<script src="../src/pixi/display/DisplayObject.js"></script>
<script src="../src/pixi/display/DisplayObjectContainer.js"></script>
<script src="../src/pixi/display/Sprite.js"></script>
<script src="../src/pixi/display/Stage.js"></script>
<script src="$path/src/Intro.js"></script>
<script src="$path/src/pixi/Pixi.js"></script>
<script src="$path/src/Phaser.js"></script>
<script src="$path/src/utils/Utils.js"></script>
<script src="../src/pixi/extras/CustomRenderable.js"></script>
<script src="../src/pixi/extras/Strip.js"></script>
<script src="../src/pixi/extras/Rope.js"></script>
<script src="../src/pixi/extras/TilingSprite.js"></script>
<script src="$path/src/pixi/core/Matrix.js"></script>
<script src="$path/src/pixi/core/Point.js"></script>
<script src="$path/src/pixi/core/Rectangle.js"></script>
<script src="$path/src/pixi/core/Polygon.js"></script>
<script src="../src/pixi/filters/AbstractFilter.js"></script>
<script src="../src/pixi/filters/BlurFilter.js"></script>
<script src="../src/pixi/filters/BlurXFilter.js"></script>
<script src="../src/pixi/filters/BlurYFilter.js"></script>
<script src="../src/pixi/filters/ColorMatrixFilter.js"></script>
<script src="../src/pixi/filters/CrossHatchFilter.js"></script>
<script src="../src/pixi/filters/DisplacementFilter.js"></script>
<script src="../src/pixi/filters/DotScreenFilter.js"></script>
<script src="../src/pixi/filters/FilterBlock.js"></script>
<script src="../src/pixi/filters/GrayFilter.js"></script>
<script src="../src/pixi/filters/InvertFilter.js"></script>
<script src="../src/pixi/filters/PixelateFilter.js"></script>
<script src="../src/pixi/filters/RGBSplitFilter.js"></script>
<script src="../src/pixi/filters/SepiaFilter.js"></script>
<script src="../src/pixi/filters/SmartBlurFilter.js"></script>
<script src="../src/pixi/filters/TwistFilter.js"></script>
<script src="$path/src/pixi/display/DisplayObject.js"></script>
<script src="$path/src/pixi/display/DisplayObjectContainer.js"></script>
<script src="$path/src/pixi/display/Sprite.js"></script>
<script src="$path/src/pixi/display/Stage.js"></script>
<script src="../src/pixi/primitives/Graphics.js"></script>
<script src="$path/src/pixi/extras/CustomRenderable.js"></script>
<script src="$path/src/pixi/extras/Strip.js"></script>
<script src="$path/src/pixi/extras/Rope.js"></script>
<script src="$path/src/pixi/extras/TilingSprite.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasGraphics.js"></script>
<script src="../src/pixi/renderers/canvas/CanvasRenderer.js"></script>
<script src="$path/src/pixi/filters/AbstractFilter.js"></script>
<script src="$path/src/pixi/filters/BlurFilter.js"></script>
<script src="$path/src/pixi/filters/BlurXFilter.js"></script>
<script src="$path/src/pixi/filters/BlurYFilter.js"></script>
<script src="$path/src/pixi/filters/ColorMatrixFilter.js"></script>
<script src="$path/src/pixi/filters/CrossHatchFilter.js"></script>
<script src="$path/src/pixi/filters/DisplacementFilter.js"></script>
<script src="$path/src/pixi/filters/DotScreenFilter.js"></script>
<script src="$path/src/pixi/filters/FilterBlock.js"></script>
<script src="$path/src/pixi/filters/GrayFilter.js"></script>
<script src="$path/src/pixi/filters/InvertFilter.js"></script>
<script src="$path/src/pixi/filters/PixelateFilter.js"></script>
<script src="$path/src/pixi/filters/RGBSplitFilter.js"></script>
<script src="$path/src/pixi/filters/SepiaFilter.js"></script>
<script src="$path/src/pixi/filters/SmartBlurFilter.js"></script>
<script src="$path/src/pixi/filters/TwistFilter.js"></script>
<script src="../src/pixi/renderers/webgl/PixiShader.js"></script>
<script src="../src/pixi/renderers/webgl/PrimitiveShader.js"></script>
<script src="../src/pixi/renderers/webgl/StripShader.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLBatch.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLFilterManager.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLGraphics.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderer.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLRenderGroup.js"></script>
<script src="../src/pixi/renderers/webgl/WebGLShaders.js"></script>
<script src="$path/src/pixi/primitives/Graphics.js"></script>
<script src="../src/pixi/text/BitmapText.js"></script>
<script src="../src/pixi/text/Text.js"></script>
<script src="$path/src/pixi/renderers/canvas/CanvasGraphics.js"></script>
<script src="$path/src/pixi/renderers/canvas/CanvasRenderer.js"></script>
<script src="../src/pixi/textures/BaseTexture.js"></script>
<script src="../src/pixi/textures/Texture.js"></script>
<script src="$path/src/pixi/renderers/webgl/PixiShader.js"></script>
<script src="$path/src/pixi/renderers/webgl/PrimitiveShader.js"></script>
<script src="$path/src/pixi/renderers/webgl/StripShader.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLBatch.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLFilterManager.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLGraphics.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLRenderer.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLRenderGroup.js"></script>
<script src="$path/src/pixi/renderers/webgl/WebGLShaders.js"></script>
<script src="../src/pixi/utils/EventTarget.js"></script>
<script src="../src/pixi/utils/Polyk.js"></script>
<script src="$path/src/pixi/text/BitmapText.js"></script>
<script src="$path/src/pixi/text/Text.js"></script>
<script src="../src/core/Camera.js"></script>
<script src="../src/core/State.js"></script>
<script src="../src/core/StateManager.js"></script>
<script src="../src/core/LinkedList.js"></script>
<script src="../src/core/Signal.js"></script>
<script src="../src/core/SignalBinding.js"></script>
<script src="../src/core/Filter.js"></script>
<script src="../src/core/Plugin.js"></script>
<script src="../src/core/PluginManager.js"></script>
<script src="../src/core/Stage.js"></script>
<script src="../src/core/Group.js"></script>
<script src="../src/core/World.js"></script>
<script src="../src/core/Game.js"></script>
<script src="$path/src/pixi/textures/BaseTexture.js"></script>
<script src="$path/src/pixi/textures/Texture.js"></script>
<script src="../src/input/Input.js"></script>
<script src="../src/input/Key.js"></script>
<script src="../src/input/Keyboard.js"></script>
<script src="../src/input/Mouse.js"></script>
<script src="../src/input/MSPointer.js"></script>
<script src="../src/input/Pointer.js"></script>
<script src="../src/input/Touch.js"></script>
<script src="../src/input/InputHandler.js"></script>
<script src="$path/src/pixi/utils/EventTarget.js"></script>
<script src="$path/src/pixi/utils/Polyk.js"></script>
<script src="../src/gameobjects/Events.js"></script>
<script src="../src/gameobjects/GameObjectFactory.js"></script>
<script src="../src/gameobjects/BitmapData.js"></script>
<script src="../src/gameobjects/Sprite.js"></script>
<script src="../src/gameobjects/TileSprite.js"></script>
<script src="../src/gameobjects/Text.js"></script>
<script src="../src/gameobjects/BitmapText.js"></script>
<script src="../src/gameobjects/Button.js"></script>
<script src="../src/gameobjects/Graphics.js"></script>
<script src="../src/gameobjects/RenderTexture.js"></script>
<script src="$path/src/core/Camera.js"></script>
<script src="$path/src/core/State.js"></script>
<script src="$path/src/core/StateManager.js"></script>
<script src="$path/src/core/LinkedList.js"></script>
<script src="$path/src/core/Signal.js"></script>
<script src="$path/src/core/SignalBinding.js"></script>
<script src="$path/src/core/Filter.js"></script>
<script src="$path/src/core/Plugin.js"></script>
<script src="$path/src/core/PluginManager.js"></script>
<script src="$path/src/core/Stage.js"></script>
<script src="$path/src/core/Group.js"></script>
<script src="$path/src/core/World.js"></script>
<script src="$path/src/core/Game.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/system/StageScaleMode.js"></script>
<script src="../src/system/Device.js"></script>
<script src="../src/system/RequestAnimationFrame.js"></script>
<script src="$path/src/input/Input.js"></script>
<script src="$path/src/input/Key.js"></script>
<script src="$path/src/input/Keyboard.js"></script>
<script src="$path/src/input/Mouse.js"></script>
<script src="$path/src/input/MSPointer.js"></script>
<script src="$path/src/input/Pointer.js"></script>
<script src="$path/src/input/Touch.js"></script>
<script src="$path/src/input/InputHandler.js"></script>
<script src="../src/math/RandomDataGenerator.js"></script>
<script src="../src/math/Math.js"></script>
<script src="../src/math/QuadTree.js"></script>
<script src="$path/src/gameobjects/Events.js"></script>
<script src="$path/src/gameobjects/GameObjectFactory.js"></script>
<script src="$path/src/gameobjects/BitmapData.js"></script>
<script src="$path/src/gameobjects/Sprite.js"></script>
<script src="$path/src/gameobjects/TileSprite.js"></script>
<script src="$path/src/gameobjects/Text.js"></script>
<script src="$path/src/gameobjects/BitmapText.js"></script>
<script src="$path/src/gameobjects/Button.js"></script>
<script src="$path/src/gameobjects/Graphics.js"></script>
<script src="$path/src/gameobjects/RenderTexture.js"></script>
<script src="../src/geom/Circle.js"></script>
<script src="../src/geom/Point.js"></script>
<script src="../src/geom/Rectangle.js"></script>
<script src="$path/src/system/Canvas.js"></script>
<script src="$path/src/system/StageScaleMode.js"></script>
<script src="$path/src/system/Device.js"></script>
<script src="$path/src/system/RequestAnimationFrame.js"></script>
<script src="../src/net/Net.js"></script>
<script src="$path/src/math/RandomDataGenerator.js"></script>
<script src="$path/src/math/Math.js"></script>
<script src="$path/src/math/QuadTree.js"></script>
<script src="../src/tween/TweenManager.js"></script>
<script src="../src/tween/Tween.js"></script>
<script src="../src/tween/Easing.js"></script>
<script src="$path/src/geom/Circle.js"></script>
<script src="$path/src/geom/Point.js"></script>
<script src="$path/src/geom/Rectangle.js"></script>
<script src="../src/time/Time.js"></script>
<script src="$path/src/net/Net.js"></script>
<script src="../src/animation/AnimationManager.js"></script>
<script src="../src/animation/Animation.js"></script>
<script src="../src/animation/Frame.js"></script>
<script src="../src/animation/FrameData.js"></script>
<script src="../src/animation/AnimationParser.js"></script>
<script src="$path/src/tween/TweenManager.js"></script>
<script src="$path/src/tween/Tween.js"></script>
<script src="$path/src/tween/Easing.js"></script>
<script src="../src/loader/Cache.js"></script>
<script src="../src/loader/Loader.js"></script>
<script src="../src/loader/LoaderParser.js"></script>
<script src="$path/src/time/Time.js"></script>
<script src="$path/src/time/Timer.js"></script>
<script src="../src/sound/Sound.js"></script>
<script src="../src/sound/SoundManager.js"></script>
<script src="$path/src/animation/AnimationManager.js"></script>
<script src="$path/src/animation/Animation.js"></script>
<script src="$path/src/animation/Frame.js"></script>
<script src="$path/src/animation/FrameData.js"></script>
<script src="$path/src/animation/AnimationParser.js"></script>
<script src="../src/utils/Debug.js"></script>
<script src="../src/utils/Color.js"></script>
<script src="$path/src/loader/Cache.js"></script>
<script src="$path/src/loader/Loader.js"></script>
<script src="$path/src/loader/LoaderParser.js"></script>
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script>
<script src="$path/src/sound/Sound.js"></script>
<script src="$path/src/sound/SoundManager.js"></script>
<script src="../src/particles/Particles.js"></script>
<script src="../src/particles/arcade/ArcadeParticles.js"></script>
<script src="../src/particles/arcade/Emitter.js"></script>
<script src="$path/src/utils/Debug.js"></script>
<script src="$path/src/utils/Color.js"></script>
<script src="../src/tilemap/Tile.js"></script>
<script src="../src/tilemap/Tilemap.js"></script>
<script src="../src/tilemap/TilemapLayer.js"></script>
<script src="../src/tilemap/TilemapParser.js"></script>
<script src="../src/tilemap/Tileset.js"></script>
<script src="$path/src/physics/arcade/ArcadePhysics.js"></script>
<script src="$path/src/physics/arcade/Body.js"></script>
<script src="$path/src/particles/Particles.js"></script>
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
<script src="$path/src/particles/arcade/Emitter.js"></script>
<script src="$path/src/tilemap/Tile.js"></script>
<script src="$path/src/tilemap/Tilemap.js"></script>
<script src="$path/src/tilemap/TilemapLayer.js"></script>
<script src="$path/src/tilemap/TilemapParser.js"></script>
<script src="$path/src/tilemap/Tileset.js"></script>
<script src="../src/PixiPatch.js"></script>
<script src="$path/src/PixiPatch.js"></script>
EOL;
?>

View file

@ -118,6 +118,7 @@
<script src="../src/tween/Tween.js"></script>
<script src="../src/tween/Easing.js"></script>
<script src="../src/time/Time.js"></script>
<script src="../src/time/Timer.js"></script>
<script src="../src/animation/AnimationManager.js"></script>
<script src="../src/animation/Animation.js"></script>
<script src="../src/animation/Frame.js"></script>

View file

@ -117,6 +117,7 @@
<script src="../src/tween/Tween.js"></script>
<script src="../src/tween/Easing.js"></script>
<script src="../src/time/Time.js"></script>
<script src="../src/time/Timer.js"></script>
<script src="../src/animation/AnimationManager.js"></script>
<script src="../src/animation/Animation.js"></script>
<script src="../src/animation/Frame.js"></script>

View file

@ -26,7 +26,7 @@ PIXI.CanvasRenderer.prototype.render = function(stage)
// if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.clearRect(0, 0, this.width, this.height)
// this.context.clearRect(0, 0, this.width, this.height)
this.renderDisplayObject(stage);
// Remove frame updates

View file

@ -42,6 +42,11 @@ Phaser.Mouse = function (game) {
*/
this.mouseUpCallback = null;
/**
* @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propogate fully.
*/
this.capture = true;
/**
* @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.
* @default
@ -165,7 +170,10 @@ Phaser.Mouse.prototype = {
this.event = event;
event.preventDefault();
if (this.capture)
{
event.preventDefault();
}
this.button = event.which;
@ -194,7 +202,10 @@ Phaser.Mouse.prototype = {
this.event = event;
event.preventDefault();
if (this.capture)
{
event.preventDefault();
}
if (this.mouseMoveCallback)
{
@ -221,7 +232,10 @@ Phaser.Mouse.prototype = {
this.event = event;
event.preventDefault();
if (this.capture)
{
event.preventDefault();
}
this.button = Phaser.Mouse.NO_BUTTON;

View file

@ -17,7 +17,7 @@
*/
Phaser.Sound = function (game, key, volume, loop) {
volume = volume || 1;
if (typeof volume == 'undefined') { volume = 1; }
if (typeof loop == 'undefined') { loop = false; }
/**
@ -416,18 +416,19 @@ Phaser.Sound.prototype = {
* @method Phaser.Sound#play
* @param {string} [marker=''] - If you want to play a marker then give the key here, otherwise leave blank to play the full sound.
* @param {number} [position=0] - The starting position to play the sound from - this is ignored if you provide a marker.
* @param {number} [volume=1] - Volume of the sound you want to play.
* @param {number} [volume=1] - Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified).
* @param {boolean} [loop=false] - Loop when it finished playing?
* @param {boolean} [forceRestart=true] - If the sound is already playing you can set forceRestart to restart it from the beginning.
* @return {Sound} The playing sound object.
* @return {Phaser.Sound} This sound instance.
*/
play: function (marker, position, volume, loop, forceRestart) {
marker = marker || '';
position = position || 0;
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
if (typeof forceRestart == 'undefined') { forceRestart = true; }
if (typeof volume === 'undefined') { volume = this._volume; }
if (typeof loop === 'undefined') { loop = false; }
if (typeof forceRestart === 'undefined') { forceRestart = true; }
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);

View file

@ -324,11 +324,12 @@ Phaser.SoundManager.prototype = {
* @param {string} key - Asset key for the sound.
* @param {number} [volume=1] - Default value for the volume.
* @param {boolean} [loop=false] - Whether or not the sound will loop.
* @return {Phaser.Sound} The new sound instance.
*/
add: function (key, volume, loop) {
volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; }
if (typeof volume === 'undefined') { volume = 1; }
if (typeof loop === 'undefined') { loop = false; }
var sound = new Phaser.Sound(this.game, key, volume, loop);
@ -336,6 +337,27 @@ Phaser.SoundManager.prototype = {
return sound;
},
/**
* Adds a new Sound into the SoundManager and starts it playing.
* @method Phaser.SoundManager#play
* @param {string} key - Asset key for the sound.
* @param {number} [volume=1] - Default value for the volume.
* @param {boolean} [loop=false] - Whether or not the sound will loop.
* @param {boolean} [destroyOnComplete=false] - If true the Sound will destroy itself once it has finished playing, or is stopped.
* @return {Phaser.Sound} The new sound instance.
*/
play: function (key, volume, loop, destroyOnComplete) {
if (typeof destroyOnComplete == 'undefined') { destroyOnComplete = false; }
var sound = this.add(key, volume, loop);
sound.play();
return sound;
}
};

View file

@ -117,7 +117,6 @@ Phaser.StageScaleMode = function (game, width, height) {
* @default
*/
this.maxIterations = 5;
/**
* @property {PIXI.Sprite} orientationSprite - The Sprite that is optionally displayed if the browser enters an unsupported orientation.
@ -145,6 +144,11 @@ Phaser.StageScaleMode = function (game, width, height) {
*/
this.leaveIncorrectOrientation = new Phaser.Signal();
/**
* @property {Phaser.Signal} hasResized - The event that is dispatched when the game scale changes.
*/
this.hasResized = new Phaser.Signal();
if (window['orientation'])
{
this.orientation = window['orientation'];
@ -163,9 +167,22 @@ Phaser.StageScaleMode = function (game, width, height) {
/**
* @property {Phaser.Point} scaleFactor - The scale factor based on the game dimensions vs. the scaled dimensions.
* @readonly
*/
this.scaleFactor = new Phaser.Point(1, 1);
/**
* @property {Phaser.Point} scaleFactorInversed - The inversed scale factor. The displayed dimensions divided by the game dimensions.
* @readonly
*/
this.scaleFactorInversed = new Phaser.Point(1, 1);
/**
* @property {Phaser.Point} margin - If the game canvas is seto to align by adjusting the margin, the margin calculation values are stored in this Point.
* @readonly
*/
this.margin = new Phaser.Point(0, 0);
/**
* @property {number} aspectRatio - Aspect ratio.
* @default
@ -471,14 +488,9 @@ Phaser.StageScaleMode.prototype = {
*/
refresh: function () {
var _this = this;
// We can't do anything about the status bars in iPads, web apps or desktops
if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false)
{
// document.documentElement['style'].minHeight = '2000px';
// this._startHeight = window.innerHeight;
if (this.game.device.android && this.game.device.chrome == false)
{
window.scrollTo(0, 1);
@ -492,9 +504,13 @@ Phaser.StageScaleMode.prototype = {
if (this._check == null && this.maxIterations > 0)
{
this._iterations = this.maxIterations;
var _this = this;
this._check = window.setInterval(function () {
return _this.setScreenSize();
}, 10);
this.setScreenSize();
}
@ -588,10 +604,12 @@ Phaser.StageScaleMode.prototype = {
{
if (this.width < window.innerWidth && this.incorrectOrientation == false)
{
this.game.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
this.margin.x = Math.round((window.innerWidth - this.width) / 2);
this.game.canvas.style.marginLeft = this.margin.x + 'px';
}
else
{
this.margin.x = 0;
this.game.canvas.style.marginLeft = '0px';
}
}
@ -600,10 +618,12 @@ Phaser.StageScaleMode.prototype = {
{
if (this.height < window.innerHeight && this.incorrectOrientation == false)
{
this.game.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
this.margin.y = Math.round((window.innerHeight - this.height) / 2);
this.game.canvas.style.marginTop = this.margin.y + 'px';
}
else
{
this.margin.y = 0;
this.game.canvas.style.marginTop = '0px';
}
}
@ -615,6 +635,11 @@ Phaser.StageScaleMode.prototype = {
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
this.scaleFactorInversed.x = this.width / this.game.width;
this.scaleFactorInversed.y = this.height / this.game.height;
this.hasResized.dispatch(this.width, this.height);
this.checkOrientationState();
},

View file

@ -146,7 +146,7 @@ Phaser.Time = function (game) {
this.game.onResume.add(this.gameResumed, this);
/**
* Description.
* Internal value used to recover from the game pause state.
* @property {boolean} _justResumed
* @default
*/
@ -156,15 +156,6 @@ Phaser.Time = function (game) {
Phaser.Time.prototype = {
/**
* The number of seconds that have elapsed since the game was started.
* @method Phaser.Time#totalElapsedSeconds
* @return {number}
*/
totalElapsedSeconds: function() {
return (this.now - this._started) * 0.001;
},
/**
* Updates the game clock and calculate the fps. This is called automatically by Phaser.Game.
* @method Phaser.Time#update
@ -241,6 +232,15 @@ Phaser.Time.prototype = {
},
/**
* The number of seconds that have elapsed since the game was started.
* @method Phaser.Time#totalElapsedSeconds
* @return {number}
*/
totalElapsedSeconds: function() {
return (this.now - this._started) * 0.001;
},
/**
* How long has passed since the given time.
* @method Phaser.Time#elapsedSince

117
src/time/Timer.js Normal file
View file

@ -0,0 +1,117 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Timer constructor.
*
* @class Phaser.Timer
* @classdesc A Timer
* @constructor
* @param {Phaser.Game} game A reference to the currently running game.
*/
Phaser.Timer = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* The time at which this Timer instance started.
* @property {number} _started
* @private
* @default
*/
this._started = 0;
/**
* The time (in ms) that the last second counter ticked over.
* @property {number} _timeLastSecond
* @private
* @default
*/
this._timeLastSecond = 0;
this.running = false;
this.events = [];
this.onEvent = new Phaser.Signal();
// Need to add custom FPS rate, for now we'll just use seconds
}
Phaser.Timer.prototype = {
// delay could be from now, when the timer is created, or relative to an already running timer
// add: function (delay, callback, callbackContext) {
add: function (delay) {
this.events.push({
delay: delay,
dispatched: false,
args: Array.prototype.splice.call(arguments, 1)
});
// this.events.push({
// delay: delay,
// dispatched: false,
// callback: callback,
// callbackContext: callbackContext,
// args: Array.prototype.splice.call(arguments, 3)
// });
},
start: function() {
this._started = this.game.time.now;
this.running = true;
// sort the events based on delay here, also don't run unless events is populated
// add ability to auto-stop once all events are done
// add support for maximum duration
// add support for delay before starting
// add signals?
},
stop: function() {
this.running = false;
this.events.length = 0;
},
update: function() {
// TODO: Game Paused support
if (this.running)
{
var seconds = this.seconds();
for (var i = 0, len = this.events.length; i < len; i++)
{
if (this.events[i].dispatched == false && seconds >= this.events[i].delay)
{
this.events[i].dispatched = true;
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
this.onEvent.dispatch.apply(this, this.events[i].args);
// ought to slice it now
}
}
}
},
seconds: function() {
return (this.game.time.now - this._started) * 0.001;
}
}