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

Adjust the offset of the key frame #1181

Closed
ngcin opened this issue Jun 27, 2022 · 5 comments
Closed

Adjust the offset of the key frame #1181

ngcin opened this issue Jun 27, 2022 · 5 comments
Assignees
Labels
type:new feature Adding a feature that isn't currently present

Comments

@ngcin
Copy link

ngcin commented Jun 27, 2022

Since the image size of each frame is different, I want to align the image of each frame by adjusting the offset of the key frame. If I modify the image, the workload is relatively large. I want to adjust it from the code level. Is there a good way?

@AlmasB
Copy link
Owner

AlmasB commented Jul 1, 2022

Hmm, that's a good question. As far as I can remember, FXGL does not support offsets for each frame. Sounds like a very useful feature to have. Can you provide a simple (ideally, minimal) demo with an appropriate sprite sheet and I'll see if we can implement this relatively soon...

@ngcin
Copy link
Author

ngcin commented Jul 2, 2022

Thanks for your reply, I submitted a simple demo at https://github.com/ngcin/fani which includes a monster's attack animation. The animation structure description is a json file (/assets/data/monster.json), and the "res" node describes each frame image position in sprite sheet, "frames" describes the offsets of the frame .

@AlmasB AlmasB self-assigned this Jul 7, 2022
@AlmasB AlmasB added the type:new feature Adding a feature that isn't currently present label Jul 7, 2022
@AlmasB
Copy link
Owner

AlmasB commented Jul 7, 2022

Thanks, I've had a quick look.

If I understand correctly, we can potentially solve this by:

  1. adding offsetX/Y to FrameData with 0 values as default.
  2. inside AnimatedTexture::updateImage() use offsetX/Y to offset the image:
    private fun updateImage() {
        val frameData = animationChannel.getFrameData(currentFrame)

        image = animationChannel.image
        fitWidth = frameData.width.toDouble()
        fitHeight = frameData.height.toDouble()
        viewport = frameData.viewport

        // offset here
    }

Would that work for your (and also general) use case?

@ngcin
Copy link
Author

ngcin commented Jul 7, 2022

Yes, entirely accurate! This is exactly what I thought, this function is very helpful for us to use existing texture materials, thank you!

@AlmasB AlmasB closed this as completed in 6cba0b4 Jul 11, 2022
@AlmasB
Copy link
Owner

AlmasB commented Jul 11, 2022

Demo here: https://twitter.com/AlmasBaim/status/1546529789946773506

To get the latest build, you can use this:

<dependencies>
    <dependency>
        <groupId>com.github.almasb</groupId>
        <artifactId>fxgl</artifactId>
        <version>17+dev-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>oss.sonatype.org-snapshot</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:new feature Adding a feature that isn't currently present
Projects
None yet
Development

No branches or pull requests

2 participants