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

loadAnimation() fails parsing filenames with short non-numeric prefix #197

Closed
myselfhimself opened this issue Feb 16, 2021 · 10 comments · Fixed by #204
Closed

loadAnimation() fails parsing filenames with short non-numeric prefix #197

myselfhimself opened this issue Feb 16, 2021 · 10 comments · Fixed by #204

Comments

@myselfhimself
Copy link
Contributor

Hello,
for a call like:
var cog1 = loadAnimation('sprites/food/level3/bricks/cog0001.png', 'sprites/food/level3/bricks/cog0002.png');
an error will be raised by p5.js:
Warning undefined frame 0

Step by step debugging of p5.play.js shows:


               var digits1 = 0;
                var digits2 = 0;

                //skip extension work backwards to find the numbers
                for (i = from.length-5; i >= 0; i--) {
                    if(from.charAt(i) >= '0' && from.charAt(i) <= '9')
                        digits1++;
                }

                for (i = to.length-5; i >= 0; i--) {
                    if(to.charAt(i) >= '0' && to.charAt(i) <= '9')
                        digits2++;
                }

// DIGITS1 AND DIGITS2 VARIABLES EVALUATE TO 5

                var prefix1 = from.substring(0, from.length-(4+digits1));
                var prefix2 = to.substring(0, to.length-(4+digits2) );

PREFIX1 AND PREFIX2 BOTH EVALUATE TO  "sprites/food/level3/bricks/co"

I suspect that the issue is related to the filename prefix is too short (cog) vs. the 4+digits1 hardcoded substring value which should be computed dynamically instead.

:)

@molleindustria
Copy link
Collaborator

Sorry, I can't reproduce that. I encounter no issues when using assets named cog0001 etc

@myselfhimself
Copy link
Contributor Author

myselfhimself commented May 26, 2021

Hello, the issue actually lies if there is one or more digits in the whole path before the file name itself.

See screenshot excerpt below:
image

In such conditions, for my file names to be taken into account.. I have to rename them with an additional padding 0 and have my loadAnimation() calls use one 0 of padding fewer as reality...

In my above comment's code excerpt, variables digits1 and digits2 should be computed on from.substr(from.lastIndexOf("/")+1) and to.substr(to.lastIndexOf("/")+1), that is to say on the filename without directory paths included.

@myselfhimself
Copy link
Contributor Author

myselfhimself commented May 26, 2021

This does not prevent me from telling you, thanks for p5.play!! It spares me a lot of work.. :)

@myselfhimself
Copy link
Contributor Author

Related to myselfhimself/BerlinWallBreaker#1

@myselfhimself
Copy link
Contributor Author

This is fixed in this PR https://github.com/molleindustria/p5.play/pull/175

@molleindustria
Copy link
Collaborator

It says there is a conflict in the PR, I have no idea of how to solve it

@myselfhimself
Copy link
Contributor Author

myselfhimself commented May 27, 2021 via email

@myselfhimself
Copy link
Contributor Author

I created a simpler PR thanks to @keithohara 's former work on PR #175 , feel free to merge.
I tested the new PR manually it works well.

molleindustria added a commit that referenced this issue May 27, 2021
#197 #175 Fixing greedy digits lookup in animation sprites file paths
@molleindustria
Copy link
Collaborator

Thank you so much!

@myselfhimself
Copy link
Contributor Author

Thank you too!

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 a pull request may close this issue.

2 participants