-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
(#6480) tiled parallax support #6714
(#6480) tiled parallax support #6714
Conversation
I went now a different route and updated the already existing I also tested it now with all map options (iso, ortho, hex) and it looks good to me. I used the |
That's a great PR! Though from previous discussions about tile/tiledmap stuff ( #6534 (comment) ) libGDX members don't really want to add Tiled Editor (TMX) specific elements to the base classes (For example |
@lyze237 I can do that but I have a question for that change. In Tiled you can have something like this: This is a grouping of layers and the final parallax scrolling factor is then the multiplication of the factor of the layer itself and all of its parents. I see there is a Since there is no common parent for Tiled specific layers I need to duplicate the parallax properties in I have no problem with that and could make those changes but should I then move the If you ask me I argue that a parallax scrolling factor should be part of the general But don't get this the wrong way. I am not an expert with the LibGDX repository and the reasoning behind certain decisions. If it is better for you to keep everything separate then as mentioned above, I can do the adjustments but please provide me with some answers to my questions :) Thank you! |
Hey! @MobiDevelop! Sorry for the ping. Since you helped with previous tile d related PRs, could you check this one out quickly and see what's the best way to add that? |
I think adding parallax properties/functionality on the base MapLayer is fine. It's a pretty common/generic need whether you use Tiled (editor) for making maps. If I recall, Tide does/did have parallax support. |
Thanks for the feedback! Let me then do some final adjustments and testing please. I try to finish it today or tomorrow and keep it in the MapLayer. edit: I am finished from my side. I had to fix the hierarchical scrolling factor loading because doing it within Also, added correct support for image layer rendering as well and reverted the changes to Please note that when you use hierarchical scrolling factors in Tiled then at the moment you get a different result in LibGDX. The reason is (as mentioned above) that there is a bug currently in Tiled which gets fixed in an upcoming version. The author mentioned that it gets fixed and is then correctly working as mentioned in the documentation. If I am not mistaken then I implemented the already fixed version according to the documentation. |
* Upgrade gradle wrapper to 6.9 * Update junit * Replace deprecated compile for dependencies * Replace deprecated archiveName with archiveFileName * Upgrade to gradle 6.9.1 * Replace compile to api in headless
This reverts commit 7ac239c.
cool stuff! Can you also verify the y-axis once more? Just to be safe. And most likely it is the same mistake in the other renderers as mentioned by @lyze237 above. Thanks for helping out :) |
Totally, when I have some time either tonight or tomorrow I'll try and test out everything that's been mentioned. Also, I'll try out the Y axis as well and report back. Luckily, I had just finished my tiled color tint PR. So I was in a good spot to help out here. |
One more follow up to this Thread. I have never used OrthoCachedTiledMapRenderer, but I do see that the cache will become false either through forced call of invalidateCache() or in the setView() method when the bounds are exceeded. That being said based on how I "think" this caching system works. I actually think that we should change this: In my repo when testing these changes and Modifying the test to FORCE a call to invalidateCache every frame, we can actually get it to work the same as all of the other renders. That being said, Orthcache seems out of date anyway and as you've stated doesnt even support layers. So I don't know if we would want to just skip it. :-/ |
I think it doesn't harm to add the functionality to the Orthocache renderer as well and from what I understood you are correct that you need to call invalidateCache before rendering to get the correct result. As mentioned at the beginning of this topic (somewhere ;) ), I'd anyway suggest that this rendering logic gets refactored because it seems to be copy&pasted to the different renderers which makes it then a little bit tidious to bring in features like this one. But I assume that this is not going to happen in the near future as this also can be a risky move to introduce bugs. So I think having it like we do it now is good enough ... just my personal point of view. Anyway, thanks for helping out @BoBIsHere86 ! Looks good to me. I requested a re-review of the two reviewers from before. Let's hope they give it a look soon so that doesn't have to lay around another year or so :) edit: btw do I need to do something with my fork? I am not very familiar with the github merging workflow and the forks. If I need to do anything, please let me know. |
I'm no git expert, I was hoping I could just propose changes in the PR for you to accept but I guess not. You need to change the ' unitScale + viewBounds.x * (layer.getParallaxX() - 1);' portion to use minus like this: That was the big oversight I noticed which caused these issues. Then if we wanted to work on the Orthocache I think we need to change : To used viewBounds instead of cacheBounds: But that being said, in order for this to show correctly in the test, you would need to add a call to invalidate the cache when using that renderer. Maybe I can just fork your fork, and see if I can just send you a PR with the changes to make this less painful. Either way this PR is a great addition it will be good to try and have libGDX fully up to date with Tiled's newest features. |
…the parallax effect works properly. Modified test maps parallax value so it was easier to see the effect. Made a change in the BaseTmxMapLoader just to keep it consistent with the rest of the code.
…ve like the rest, also changed using cacheBounds to determine parallax to using viewBounds like the rest. Also modified the ortho map to have a non group parallax layer. so it will show up in OrthoCachetest
Just cherry-picked the commits from Quillraven#1. I hope I didn't forget something |
Awesome, Looks like you got everything. Great to see this moving along. |
So I don't need to do anything here? Thank you again for the support guys! If I still need to do something then let me know. I should have some time on the weekend 🙂 |
I finally had now a little time to look into this topic (fixes #6480) and had a discussion with the guy from Tiled to understand better how Tiled is implementing parallax scrolling. You can find the discussion here.
However, I seek for your help guys because I am a little bit overwhelmed by the big amount of different renderers and where exactly I should put the code.
For testing, I have adjusted the existing
ortho.tmx
file and added some group layers with different parallax factors to also test the correct behavior of "structured" layers where the final scrolling factor is the layer's factor multiplied by its parents.My approach is done in the map loader directly. Whenever a parent is set, which seems to happen after its children are loaded then the parallax value is simply multiplied by the parent's parallax value. That should support that use case correctly but please note that the Tiled author mentioned that this is currently bugged and will be fixed in an upcoming version. But that should not stop us from implementing it correctly ;)
Next I tried to update the render logic. I see there is a
TiledMapRenderer
interface which I assume is used by all renderers related to the Tiled Editor?There are two implementations of this interface:
BatchTiledMapRenderer
andOrthoCachedTiledMapRenderer
.I saw that the second one does not correctly support group layers and also the render code seems to be copy pasted which is also not ideal.
render()
andrender(int[] layers)
has 99% the same code from what I can tell and should be merged.But anyway, it seems like this renderer is not up to date and therefore I ignored it for now.
The
BatchTiledMapRenderer
is then subclassed by a few other renderers likeHexagonalTiledMapRenderer
orOrthogonalTiledMapRenderer
.Since parallax scrolling should be a generic solution for any renderer in my opinion I put my code in the
BatchTiledMapRenderer
hoping that this will then apply to all subclasses but I did not verify that yet, sorry.My idea was to put it into the
renderMapLayer
method to also apply the logic to any type of layer because in my opinion it should always behave the same. It simply renders the layer with a specific offset no matter if it is a tiled, object or image layer.I currently use the transform matrix of the
batch
and apply a specific translation but this has the disadvantage that I have to break the rendering process withend
andbegin
which I guess has a negative impact on the render performance?I used the existing
TiledMapLayerOffsetTest
to test the changes. It does already a parallax render effect but it does not 100% match the result I get in Tiled. The problem is I am missing some information in Tiled and therefore it is hard for me to understand where the difference is coming from.Anyway, please have a look and let me know how to do it properly and efficiently.
Edit: I noticed that there is also some weird clipping happening and the parallax layer sometimes get cut off although it is within the view. Will need to have a look at that as well. I thought with using the translate functionality on the batch I should be safe but doesn't seem so 😅