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

add animWidth and animHeight to limit frame cycles of individual anim… #77

Merged
merged 3 commits into from
Mar 3, 2020
Merged

add animWidth and animHeight to limit frame cycles of individual anim… #77

merged 3 commits into from
Mar 3, 2020

Conversation

blurymind
Copy link
Contributor

@blurymind blurymind commented Feb 25, 2020

This adds the ability to (cheaply) limit individual animated frame cycles to their respective animated frame strips width and height.
frameCycle
The coin has 9 consecutive frames, the viking on the right has 5, the grass has three.
The viking in the middle is the edge case that I plan to fix with a different workaround - he is the one that has frames scattered at different locations on my tileset

It is a part of an effort to get #3 and #76 sorted to a pleasing level as well as bundle pixi-tilemap with gdevelop game engine
4ian/GDevelop#503

I explain why this is required here
#76 (comment)

Here is an entire tmx file data parsed scene (from a json file actually, exported by tiled), rendered entirely via pixi-tilemap
pixi-tilemap-parsing-tmx-data

with several layers of animated and non animated tiles + objects and object groups

@blurymind
Copy link
Contributor Author

blurymind commented Feb 25, 2020

I think my mod method or the way I increment time is not right.
The frames go like this(wrong order)
1,3,5,2,4,6

TILEMAP.addFrame(
                      TILESET.getFrame(tileUid),
                      xPos,
                      yPos,
                      1,
                      0,
                      tileFrameCount * tileWidth
                    );
....
app.renderer.plugins.tilemap.tileAnim[0] += tileWidth;

this could also be a case of me giving it wrongly parsed tiled data

Can you help me with the mod method? Does it seems correct to you? Or is this a case of me incrementing time wrong?

EDIT: apologies, I have made a piskae with how I was initiating my pixi scene. My update function was not nested properly. There is nothing wrong with the modulo frame cycling - it works as intended

@ivanpopelyshev
Copy link
Collaborator

Need more data. do you use both X and Y animations or only one of those directions?

@blurymind
Copy link
Contributor Author

Need more data. do you use both X and Y animations or only one of those directions?

Sorry I just had realized that I made an error outside of this pr- with how I was initiating my pixi scene. Updated my previous post.

The feature here works as intended

@ivanpopelyshev
Copy link
Collaborator

PR looks fine but I'm too tired to merge and rebuilt it now :( i will try tomorrow

@blurymind
Copy link
Contributor Author

blurymind commented Feb 25, 2020

Here is a sneak peek:
frameCycle
The coin has 9 consecutive frames, the viking on the right has 5,
The viking in the middle is the edge case that I plan to fix with a different workaround - he is the one that has frames scattered at different locations on my tileset

Sorry for choppines, my recording software sucks

Thank you in advance for the patience on my rantings and also for reviewing this. I really hope that we will be able to get gdevelop to become the second big game engine to use this library,potentially bringing more contributors like me to this tracker

@blurymind
Copy link
Contributor Author

blurymind commented Mar 1, 2020

@ivanpopelyshev have youmanaged to find some time for this?
Here is an online demo
https://blurymind.github.io/yet-another-pixi-webpack-boilerplate/docs/
Its using pixi-tilemap with this patch

All the map data comes from an example tmx file

@ivanpopelyshev
Copy link
Collaborator

Nooo so many guys in need! Good demo though, i hope i can merge this thing soon

@blurymind
Copy link
Contributor Author

blurymind commented Mar 2, 2020

It's strange, the grass breaks on windows, unless I change the modulo function to
vec2 anim = aAnim * mod(animationFrame + 1.0, vec2(aAnimWidth, aAnimHeight))

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Mar 2, 2020

its a corner case, because those are floats, not ints. It can be different a bit in Intel HD :) I usually add 0.5 there. Basically, "4 = 0 * 4 + 3.9999" or "4 = 1 * 4 + 0 " . I just add 0.5 before and after the operation.

@blurymind
Copy link
Contributor Author

will my change fix it for most hardware?

@blurymind
Copy link
Contributor Author

blurymind commented Mar 2, 2020

Here is an updated tutorial repository
https://blurymind.github.io/pixi-tilemap-tutorial/
https://github.com/blurymind/pixi-tilemap-tutorial

You can add it to the readme if you like :)

@blurymind
Copy link
Contributor Author

blurymind commented Mar 2, 2020

its a corner case, because those are floats, not ints. It can be different a bit in Intel HD :) I usually add 0.5 there. Basically, "4 = 0 * 4 + 3.9999" or "4 = 1 * 4 + 0 " . I just add 0.5 before and after the operation.

how would that look in the context of
vec2 anim = aAnim * mod(animationFrame, vec2(aAnimWidth, aAnimHeight))
where I have vec2? :)

just adding 1.0 to animationFrame seems to fix it completely without making a visual difference

Btw I'm glad I got to test in more hardware and catch this before it getting out

@ivanpopelyshev
Copy link
Collaborator

OK, gonna merge it but i'll fix stuff before i publish it.

@ivanpopelyshev ivanpopelyshev merged commit 694f4a9 into pixijs:v4.x Mar 3, 2020
@blurymind
Copy link
Contributor Author

blurymind commented Mar 3, 2020 via email

@ivanpopelyshev
Copy link
Collaborator

I'm working on it.

@blurymind
Copy link
Contributor Author

blurymind commented Mar 3, 2020 via email

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Mar 3, 2020

gimme access to tutorial!

@blurymind
Copy link
Contributor Author

gimme access to tutorial!

sent you an invite 👍

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

Successfully merging this pull request may close these issues.

2 participants