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

pixi-tilemap assigns wrong width and height to the object when there are empty tiles #108

Closed
blurymind opened this issue Feb 2, 2021 · 8 comments

Comments

@blurymind
Copy link
Contributor

Gdevelop's wrapper for pixi-tilemap uses the width/height value of the object to draw a boundary box.
It appears that pixi-tilemap's width and height values are wrong whenever the tilemap has empty tiles, resulting in a smaller boundary box.
see
4ian/GDevelop#503 (comment)

@ivanpopelyshev
Copy link
Collaborator

How width/height is calculated: https://github.com/pixijs/pixi-tilemap/blob/master/src/RectTileLayer.ts#L105

For every tile you add, minX maxX is calculated.

What exactly is empty tile?

@ivanpopelyshev
Copy link
Collaborator

If you mean that "tilemap should store width/height independently and ignore tiles that go out of those bounds" - no, sorry, those fields are calculated , its your problem to store width/height you want in your own tilemap. If you guys want different w/h - override the setter getter, like its done in pixi TilingSprite or Sprite

@ivanpopelyshev
Copy link
Collaborator

also you can override calculateBounds of CompositeRectTileLayer or just RectTileLayer to take your own _$_width _$_height local vars , for example.

@blurymind
Copy link
Contributor Author

blurymind commented Feb 9, 2021

Thank you for explaining :)

I did a manual calculation on gdevelop's wrapper for pixi-tilemap, but it would be nice if we could have these be calculated and stored by pixi-tilemap somewhere :)
Having the absolute width/height of the resulting tilemap is very useful when used in game engines which require it.

Gdevelop uses this to do the bounding box of the object, which has an effect on

  • whether the object gets rendered at all (if the bounding box is incorrect size, this leads to gdevelop thinking its not in the camera view and it doesnt render it at all sometimes)
  • being able to select the tilemap in the engine's IDE - to move and resize it

@blurymind
Copy link
Contributor Author

I am silly, we never add these empty tiles to pixi tilemap - so it has nothing to work with for estimating proper boundaries.

@ivanpopelyshev I think I will close this bug, the fault is in the wrapper- since it never tells pixi-tilemap about them. But how do we tell to pixi-tilemap to change it's width/height externally? That would be incredibly useful for our case

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Feb 9, 2021

override calculateBounds() to add minX/maxX/minY/maxY that you specify in it :) , just use addFramePad two times - one for real tiles , one for your extra bounds

@ivanpopelyshev
Copy link
Collaborator

At the same time, you have to do something about "width/height" property, if you want to use it for your own set bounds, and not pixi calculated ones.

@blurymind
Copy link
Contributor Author

blurymind commented Feb 9, 2021

@ivanpopelyshev you make it sound like it would be simpler to just store it in my wrapper's variables - like I did on the PR at gdevelop 😄

sorry for raising a false alarm, took me a bit to realize it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants