-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat(AnimatedSprite): add AnimatedSprite #331
Conversation
Run & review this pull request in StackBlitz Codeflow. |
✅ Deploy Preview for cientos-tresjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @andretchen0 this is a nice work, thank you so much. To be honest regarding code, almost nothing. I would like to know something.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know is a draft, a look really nice, I want to use this one!
/> | ||
``` | ||
|
||
### Ranges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I get confused, I tough ranges
was a prop maybe to put, animations as range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Thanks for the feedback. It's a good catch. I'll clear that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it clearer now?
(Fwiw, the range is supposed to be given as the animation
prop. Just in case that's still not clear.)
|
||
A `[number, number]` range can be supplied as the `animation` prop. The numbers correspond to the position of the frame in the `atlas` `frames` array, starting with `0`. The first `number` in the range represents the start frame of the animation. The last `number` represents the end frame. | ||
|
||
### Single frame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@JaimeTorrealba Thanks for the feedback! |
We can do something different, but I copied the Drei setup here. Afaik, without an atlas, the Drei version only allows for a single row of images — with all the sprites being the same size, evenly spaced, and e.g., no padding on the spritesheet itself. We could take That would work for the first row of your example spritesheet, I think. And that's an ok change in my book as far as I can see at the moment. Wherever we do, unfortunately spritesheets in the wild tend to be complied irregularly, and often distributed without an atlas. We could make an atlas builder tool that lets people divide up an already complied spritesheet, but I don't think we'd want to support that in the long term. Probably the best thing to do for irregular spritesheets without an atlas is to type out an atlas. But I understand that's not ideal for a lot of users. Open to additional ideas. But I'll go ahead and add row/cols like above unless there's an unforeseen problem. |
I'd be ok with that. I defaulted to The current implementation of
Maybe this can be worked around though. Let me know what you think. |
Exactly we don't want to support another library (still if there is another free good option, we can send the user there, having a warning that is not under our scope). Regarded asSprite as default I would expect to behave like sprite materials (but I could be wrong, maybe let's ask to someone else) |
Gotcha. Here's the only way I know that will work for spriters resource rips:
At least, that's the only solution that I see. @JaimeTorrealba the rest of this is just details about the problem. Feel free to skip. I'm just including it because I don't want you to feel like I'm dismissing your use case. I've banged my head against the wall with spritesheets from spriters resource before. I think they're mostly compiled by hand from screenshots or other means. As far as I can tell, their purpose is to distribute art to fans, not to make it easy to animate – because they don't include information for animation, i.e., how individual frames line up. Normally, some care has to be taken to get the animation frames to line up. E.g., here's Wesnoth's documentation for sprite creators.
https://wiki.wesnoth.org/Creating_Unit_Art#Basic_unit_image_specifications That gets lost in spriters resource rips. Without that information, there's no way to automate the animation, as far as I know. I'd love to be wrong though – it'd be great for our users. So if you see a way to use spriters resource spritesheets without recompiling the spritesheet/atlas, don't hesitate to tell me. That would be a welcome thing for me to learn! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, I made some comments, all non-blocking
- Why is this PR in draft? What else is missing?
Do we want to merge in v3 or wait for v4? There are no conflicts with v3, but if we wait for v4, |
I thought this one was for the v4 (but depend on you, my friend) Alvaro is coming the 19th. We have time since v4 comes in the second Q approx. If you decide to merge for the v4 remember to point to the v4 branch and add the tag :) |
Thanks for the pointers! 😀 And thanks for the PR approval. I'll wait for v4 then. That'll give us one more thing to announce. |
Hello @andretchen0, please remember to change the target branch to v4. |
Hey @JaimeTorrealba , I updated Changes to pay attention to are in the recent commit titles. But namely:
Thanks! |
Hey there @andretchen0 @JaimeTorrealba is this ready to merge? |
Merged! |
Docs:
pnpm run docs:dev
and then => http://localhost:5173/guide/abstractions/animated-sprite.htmlPlayground:
pnpm run playground
and then => http://localhost:5173/abstractions/animated-sprite@JaimeTorrealba , @alvarosabu
I wonder if you guys would take a look at
<AnimatedSprite />
while it's still a draft and give me some feedback.What do you think of the API?
I'd like to know if you see any improvements to make to the API. I followed most of what Drei did, but included a few extra things that I picked up from using Deepnight's gameBase. Maybe those changes aren't necessary here – What do you think?
In particular, these props:
onFrame
– Drei makes a new object and sends it as an argument to the callbacks. The object includes the frame name and the whole frame – e.g., the height and width of the original sprite image. I find the frame is pretty useless for the end user, so I just provide the frame name. (I don't retain the original frame info at all. I convert the values to uv coordinates, so that doesn't have to be done every tick.) Any thoughts about that?Do we want to include a spritesheet compiler?
A while ago, I wrote a very dumb node.js command line app for compiling spritesheets/atlas JSON from source images. I could rewrite it for the browser and include it in the docs. That would let users compile their own spritesheets/atlas JSON online with a drag and drop interface. But do we want to support that going forward?
TexturePacker is paid software. For context, Drei and our
<AnimatedSprite />
read simple TexturePacker atlas JSON.But Drei and our
<AnimatedSprite />
don't/won't support most of the advanced features of TexturePacker.