Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine Not Rendering TileMap Full Screen #904

Closed
jlbeard84 opened this issue Oct 24, 2017 · 10 comments
Closed

Engine Not Rendering TileMap Full Screen #904

jlbeard84 opened this issue Oct 24, 2017 · 10 comments
Assignees
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@jlbeard84
Copy link

jlbeard84 commented Oct 24, 2017

Steps to Reproduce

  1. Create TileMap with cells that make it wider than half of the canvas
  2. Add TileMap to a Scene
  3. Start engine

Expected Result

Tilemap is rendered to the width of the canvas

Actual Result

Tilemap is rendered to the last cell that at the point of half the width of the canvas

Environment

  • browsers and versions: Chrome (61.0.3163.100)
  • operating system: Windows 10 / Mac OS 10.13
  • Excalibur versions: 0.13.1

Context

I'd like to render a TileMap that represents the background for a 2D game with an overhead view. As such, I'd like it to be the full size of the canvas (minus space for a HUD). I've done some basic troubleshooting and believe the issue lies in the screenToWorldCoordinates method on Engine. I created a class that derived from Engine and copied the contents of this method into it. If I comment out the line newX = newX - this.getDrawWidth() / 2; it renders as expected.

Proposal

I might be missing something, but I don't see why the engine is determining the width of the drawable space without taking into account the zoom level; it appears to be arbitrarily halving it. Checking zoom level here seems to be appropriate.

@bferguson3
Copy link

We were both seeing this on both of our respective projects, which is strange because @jlbeard84 is rendering using a hand-built TileMap and I am using the -tiled extension.

In both cases, our individual TileMaps had the following property:
_onScreenXEnd = 27

Which didn't seem to change regardless of TileMap size, game canvas size, etc.
Thanks!

@eonarheim eonarheim assigned eonarheim and kamranayub and unassigned eonarheim Oct 24, 2017
@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Oct 24, 2017
@kamranayub
Copy link
Member

kamranayub commented Oct 25, 2017

Can you include some screenshots and isolated test cases (CodePen/JSFiddle) for us to troubleshoot?

Something must be different from the last time we successfully used TileMap (http://excaliburjs.com/ludum-38) and now for this to be an issue...

@jedeen jedeen added this to the 0.14.0 Release milestone Oct 25, 2017
@jlbeard84
Copy link
Author

Sure, I'll write a couple and add them here.

@bferguson3
Copy link

screen shot 2017-10-27 at 1 43 04

I'm layering a new tilemap over the screen for a UI.
Code is not complex:

export function LoadWindows(){
   combatWindows.x += 250; //exact pixel measurements for testing
   combatWindows.y += 360;
   game.currentScene.add(combatWindows);
}

Pretty sure this is at least related to the problem, excalibur.js @ 8241:

TileMap.prototype.update = function (engine, delta) {
            this.emit('preupdate', new Events.PreUpdateEvent(engine, delta, this));
            var worldCoordsUpperLeft = engine.screenToWorldCoordinates(new Algebra_16.Vector(0, 0));
            var worldCoordsLowerRight = engine.screenToWorldCoordinates(new Algebra_16.Vector(engine.canvas.clientWidth, engine.canvas.clientHeight));
            this._onScreenXStart = Math.max(Math.floor(worldCoordsUpperLeft.x / this.cellWidth) - 2, 0);
            this._onScreenYStart = Math.max(Math.floor((worldCoordsUpperLeft.y - this.y) / this.cellHeight) - 2, 0);
            this._onScreenXEnd = Math.max(Math.floor(worldCoordsLowerRight.x / this.cellWidth) + 2, 0);
            this._onScreenYEnd = Math.max(Math.floor((worldCoordsLowerRight.y - this.y) / this.cellHeight) + 2, 0);
            this.emit('postupdate', new Events.PostUpdateEvent(engine, delta, this));
 };

The engine is outputting _onScreenXStart as 6. This is accurate for the way the code is written, but it should obviously be 0.

There's no way to manually override this var - in the meantime this is being debugged, to save me from making a brand new branch, do you think you could make these _onscreen vars protected instead of private?

Thanks

@kamranayub
Copy link
Member

kamranayub commented Oct 28, 2017 via email

@kamranayub
Copy link
Member

kamranayub commented Nov 7, 2017

@jlbeard84 Sorry, I'm a little confused by the steps to repro.

Do you mean use a cell size that is wider than half the canvas? So two tiles == canvas width?

I was hoping to see some code I could run to debug since I'm not really understanding the bug from the descriptions here, I'm obviously missing some context. I'd like to actually run the code locally and step through it to understand what you're expecting vs. what the engine is doing.

Could either of you use https://codesandbox.io or https://codepen.io (or a fresh GitHub repo) to showcase the issue?

@jlbeard84
Copy link
Author

Sorry, been busy and forgot that I needed to do this. I'll see if I can replicate on codepen.

@jlbeard84
Copy link
Author

@kamranayub It was easier to just create a new repo. I replicated the issue here. I commented the mapColumn variable to show you how to duplicate. Please let me know if you have any questions!

https://github.com/jlbeard84/excalibur-display-issue

@kamranayub
Copy link
Member

kamranayub commented Nov 7, 2017 via email

@eonarheim
Copy link
Member

Hi @jlbeard84,

I've taken a look at this and it definitely is a bug. I think I might have found a work around, if you keep your tilemap x,y coordinates positive and adjust the camera things seem to work as expected. I think there is an issue with offscreen culling when the x,y coordinates are negative.

I've opened a PR with a workaround jlbeard84/excalibur-display-issue#1

Let me know if this helps!

image
image

image

@jedeen jedeen modified the milestones: 0.14.0 Release, 0.15.0 Release Dec 1, 2017
@jedeen jedeen modified the milestones: 0.15.0 Release, 0.16.0 Release Feb 13, 2018
jedeen pushed a commit that referenced this issue Mar 31, 2018
Corrects the culling logic for the x-axis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

No branches or pull requests

5 participants