Skip to content

Commit

Permalink
move the test on floating coordinates to the me.Camera2d.isVisible() …
Browse files Browse the repository at this point in the history
…function

also allow for #943 to be fixed in a single place, and makes other code cleaner
  • Loading branch information
obiot committed Sep 27, 2018
1 parent 1532ee2 commit 571264e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/camera/camera2d.js
Expand Up @@ -573,7 +573,12 @@
* @return {Boolean}
*/
isVisible : function (obj) {
return obj.getBounds().overlaps(this);
if (obj.floating === true) {
// #943
return true;
} else {
return obj.getBounds().overlaps(this);
}
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/particles/particlecontainer.js
Expand Up @@ -68,7 +68,7 @@
var viewport = me.game.viewport;
for (var i = this.children.length - 1; i >= 0; --i) {
var particle = this.children[i];
particle.inViewport = this.floating || viewport.isVisible(particle);
particle.inViewport = viewport.isVisible(particle);
if (!particle.update(dt)) {
this.removeChildNow(particle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderable/container.js
Expand Up @@ -796,7 +796,7 @@
obj.inViewport = false;
// iterate through all cameras
me.state.current().cameras.forEach(function(camera) {
obj.inViewport |= isFloating || camera.isVisible(obj);
obj.inViewport |= camera.isVisible(obj);
});

// update our object
Expand Down
18 changes: 18 additions & 0 deletions tests/spec/camera-spec.js
Expand Up @@ -33,4 +33,22 @@ describe("me.Camera2d", function () {
expect( result.x ).toBeCloseTo(250);
expect( result.y ).toBeCloseTo(150);
});

it("isVisible function test", function () {
// default camera
var camera = new me.Camera2d(0, 0, 1000, 1000);
var obj = new me.Renderable(0, 0, 10, 10);

// check if obj is visible
expect(camera.isVisible(obj)).toEqual(true);
// update position so that it's not just 0
camera.move(100, 100);
// check if obj is visible
expect(camera.isVisible(obj)).toEqual(false);
// set as floating
obj.floating = true;
// should be visible again
expect(camera.isVisible(obj)).toEqual(true);

});
});

0 comments on commit 571264e

Please sign in to comment.