Skip to content

Commit

Permalink
[#294] Fix floating objects in nested containers
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte committed Oct 26, 2013
1 parent 2c30696 commit edca542
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/renderable/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
*/
var globalTranslation = new me.Rect(new me.Vector2d(), 0, 0);

/**
* A global "floating entity" reference counter for nested ObjectContainers
* @ignore
*/
var globalFloatingCounter = 0;

/**
* EntityContainer represents a collection of child objects
* @class
Expand All @@ -24,8 +30,6 @@
* @param {Number} [w=me.game.viewport.width] width of the container
* @param {number} [h=me.game.viewport.height] height of the container
*/


me.ObjectContainer = me.Renderable.extend(
/** @scope me.ObjectContainer.prototype */ {

Expand Down Expand Up @@ -511,15 +515,18 @@
var x;
var y;
var viewport = me.game.viewport;

for ( var i = this.children.length, obj; i--, obj = this.children[i];) {
if (isPaused && (!obj.updateWhenPaused)) {
// skip this object
continue;
}

isFloating = this.floating || obj.floating;


if (obj.floating) {
globalFloatingCounter++;
}
isFloating = (globalFloatingCounter > 0);

// Translate global context
isTranslated = (obj.visible && !isFloating);
if (isTranslated) {
Expand All @@ -541,7 +548,12 @@
if (isTranslated) {
globalTranslation.translate(-x, -y);
}

if (globalFloatingCounter > 0) {

This comment has been minimized.

Copy link
@parasyte

parasyte Nov 11, 2013

Author Collaborator

Good catch. Actually globalFloatingCounter needs to be incremented if globalFloatingCounter > 0:

if (globalFloatingCounter > 0 || obj.floating) {
    globalFloatingCounter++;
}
globalFloatingCounter--;
}
}

return isDirty;
},

Expand All @@ -562,13 +574,11 @@

// translate to the container position
context.translate(this.pos.x, this.pos.y);

for ( var i = this.children.length, obj; i--, obj = this.children[i];) {

if ((obj.inViewport || this.floating) && obj.isRenderable) {

isFloating = this.floating || obj.floating;

isFloating = obj.floating;
if ((obj.inViewport || isFloating) && obj.isRenderable) {

if (isFloating === true) {
context.save();
// translate back object
Expand All @@ -588,7 +598,7 @@
this.drawCount++;
}
}

// restore the context
context.restore();
}
Expand Down

0 comments on commit edca542

Please sign in to comment.