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

Can this be used with an atlas? #18

Open
tobyselway opened this issue Aug 15, 2024 · 10 comments
Open

Can this be used with an atlas? #18

tobyselway opened this issue Aug 15, 2024 · 10 comments

Comments

@tobyselway
Copy link

Hi, great crate!

I'm making a top-down dungeon, where the levels are made up of tiles, and my tiles are all in a single spritesheet.
I've created a separate spritesheet with textures only representing collisions in order to be able to define which parts of each tile are wall/floor.
Is it possible to load this spritesheet into bevy_collider_gen with an index of a tile, and have it generate a polyline for that specific tile? Or will I have to split my spritesheet up into separate image files?

@shnewto
Copy link
Owner

shnewto commented Aug 15, 2024

Hello! Thank you!

If I'm understanding correctly, you can use multi_polyline_collider_translated to generate colliders for all the sprites in your image/spritesheet at once, it returns a Vec<Collider>

If I'm not understanding correctly I could use some more details and maybe a sample image 😄

@tobyselway
Copy link
Author

12

This is one of the collision tiles. By placing this in a spritesheet and processing it at once, won't I get a Vec containing 3 separate colliders?

How can I then distinguish between which ones pertain to each tile?

@shnewto
Copy link
Owner

shnewto commented Aug 15, 2024

🤔 yeah you would in that case. Is the issue then not wanting 3 separate colliders for that tile? Or is distinguishing the colliders the root of it?

@tobyselway
Copy link
Author

3 colliders for that tile makes sense. The issue is distinguishing that those 3 colliders are related to this specific tile, as they'll be in the vector alongside all the other colliders from the spritesheet.

@shnewto
Copy link
Owner

shnewto commented Aug 16, 2024

ahh okay yeah I'm understanding now, yeah that's a challenge to do with this crate as it is today.

I think there are folks achieving something similar using the crate this one depends on edges, where you can pass bytes directly to the Edges::march_edges function. You'd need to read your image then do a bit of bytes and offsets juggling to pass each tile's bytes in at a time. The physics engines this crate supports just want points in drawing order and march_edges will return that for you to pass to them directly.

I do like the idea of being able to specify things specifically in a spritesheet though and not generating colliders for entire images. I'll start thinking about how to support it without needing too much extra work from the user. If this crate did what you were hoping already, how are you imagining you'd be able to specify an individual sprite in a sprite sheet, something like specifying size, width, and offset?

@tobyselway
Copy link
Author

Something like that, yes. Ideally an index only, the same way a SpritesheetBundle's texture is specified.
Feel free to reach out if you'd like some assistance in implementing this. I'm not currently blocked by this so there's no pressure

@shnewto
Copy link
Owner

shnewto commented Aug 21, 2024

Ah okay, that's a great pointer. I'll see if I can use the SpritesheetBundle as a reference. I'll take a pass at it and tag you in a comment and maybe you can let me know if I'm on the right track for what you're imagining.

@salam99823
Copy link
Contributor

Hi, how about adding a function to get edges from bevy_math::rect::URect or adding an area argument to edges::Edges::image_edges, then adding DynamicColliderPlugin and DynamicCollider component to bevy_collider_gen.

@shnewto
Copy link
Owner

shnewto commented Nov 13, 2024

@salam99823 I think I like the idea of adding something to edges like Edges::from_grid with the same signature Bevy uses here to generate a texture atlas

Then it does get sort of tricky here in bevy_collider_gen because the caller might want more than one collider for the sprites in the atlas so we'd need to make a clean way for this crate to make it easier than just using the edges crate themselves 🤔

@shnewto
Copy link
Owner

shnewto commented Nov 13, 2024

I think you're right about something like DynamicCollider, maybe it's an object that once instantiated with an atlas, you need to specify the collider type in order to get the value at index i

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

No branches or pull requests

3 participants