From ff6ae4aabdb224307bed8a7b71fb23037e843bf5 Mon Sep 17 00:00:00 2001 From: inateno Date: Sat, 4 Nov 2017 14:36:45 +0100 Subject: [PATCH] #11 WIP z modifier on GameObject scaling --- js/engine/classes/GameObject/GameObject.js | 1 + .../classes/GameObject/GameObject.scale.js | 25 +++++++++++++++++++ js/engine/config.js | 3 +++ js/game1/Game.js | 2 ++ 4 files changed, 31 insertions(+) diff --git a/js/engine/classes/GameObject/GameObject.js b/js/engine/classes/GameObject/GameObject.js index 35cec12..77d56f1 100644 --- a/js/engine/classes/GameObject/GameObject.js +++ b/js/engine/classes/GameObject/GameObject.js @@ -351,6 +351,7 @@ function( } , set: function( z ) { this._z = z; + this._updateZScale(); if ( this.parent ) { this.parent._shouldSortChildren = true; diff --git a/js/engine/classes/GameObject/GameObject.scale.js b/js/engine/classes/GameObject/GameObject.scale.js index 9aea722..7529b9b 100644 --- a/js/engine/classes/GameObject/GameObject.scale.js +++ b/js/engine/classes/GameObject/GameObject.scale.js @@ -1,10 +1,12 @@ define( [ 'DE.GameObject' , 'DE.Time' + , 'DE.config' ], function( GameObject , Time + , config ) { /** @@ -21,6 +23,29 @@ function( return this; }; + /** + * when z change we restore saved scale, then change it again to final values and update worldScale + * @private + * @memberOf GameObject + */ + GameObject.prototype._updateZScale = function() + { + // this come from old Camera render (working fine as excepted...) + // zMaxDepth is 10 by default so if z is 1 scale modifier will be 0.9 (1 - 0.1) + var zscale = 1 - ( this.z / config.zMaxDepth ); + this._zscale = zscale; + + this.scale.x = zscale * this.savedScale.x; + this.scale.y = zscale * this.savedScale.y; + + // update worldScale + this._updateWorldScale(); + for ( var i = 0; i < this.gameObjects.length; ++i ) + { + this.gameObjects[ i ]._updateWorldScale(); + } + }; + /** * when we change the scale manually, we need to re-apply z deformation * directly save the old scale before zscale applies (this way we can recalculate things from the beginning) diff --git a/js/engine/config.js b/js/engine/config.js index db495c7..3d40890 100644 --- a/js/engine/config.js +++ b/js/engine/config.js @@ -7,6 +7,9 @@ define( [], function() , DEBUG_LEVEL: 0 }; + // zMaxDepth is the global scaling used for z. 10 by default so if you put an object to z = 10 his scale will be 0 + config.zMaxDepth = 10; + config.notifications = { enable: true // notifications enable by default ,gamepadEnable : true diff --git a/js/game1/Game.js b/js/game1/Game.js index b54d59f..392536e 100644 --- a/js/game1/Game.js +++ b/js/game1/Game.js @@ -146,10 +146,12 @@ function( DE ) Game.heart1 = new DE.GameObject( { x: 700, y: 100 + , zindex : 10 ,renderer: new DE.TextureRenderer( { spriteName: "heart" } ) } ); Game.heart2 = new DE.GameObject( { x: 800, y: 100 + , zindex : 10 ,renderer: new DE.TextureRenderer( { spriteName: "heart", width: 50, height: 20 } ) } );