Rework HitBox to support multiple named collision regions#2835
Rework HitBox to support multiple named collision regions#2835Cleptomania wants to merge 1 commit intodevelopmentfrom
Conversation
Replaces the single-polygon HitBox with a multi-region system where each HitBox can contain named Point2List regions. This enables sprites to have distinct collision shapes (e.g. separate head/body/feet hitboxes) while maintaining backward compatibility with the single-region API. Key changes: - HitBox accepts either a Point2List (single "default" region) or a dict[str, Point2List] mapping region names to point lists - Merge RotatableHitBox into HitBox (removed RotatableHitBox) - Add serialization support (save/load to JSON, with gzip option) - Update collision detection, pymunk physics, sprite lists, and tilemap to work with multi-region hitboxes - Add sprite_multi_hitbox example - Fix type annotations for pyright/mypy compatibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Right now this has a re-work that gets rid of the split between HitBox and RotatableHitBox. Originally this split was decided on because hitboxes are expensive to rotate, but in practice we've not really realized any gains from this, and everything is nearly universally always using RotatableHitBox anyways, so I think this split is not worth the headaches it has caused. In addition to removing that split, it supports multiple polygons per hitbox, and they can be named. Yet to be done is to allow the collision detects to report what regions were collided, so you could do things like check if a The new hitboxes also support being loaded from JSON, I have plans to build an editor for creating these points, but that is not done yet. Another thing yet to be done, is to update the Tilemap loading to support loading multiple regions from Tiled objects, this is something Tiled supports but Arcade has historically ignored. I will have to investigate how the region naming should work for loading these, but I believe the objects in Tiled can be given names, so that will probably be the way to go. |
| def angle(self) -> float: | ||
| """ | ||
| The angle to rotate the raw points by in degrees | ||
| def to_dict(self) -> dict: |
There was a problem hiding this comment.
Does it make sense to create a TypedDict 🤔
There was a problem hiding this comment.
Yeah I think it probably does, I’m a big fan of TypedDict for things that are being saved/loaded. Especially if that format somehow gets expanded to have more metadata that an editor might make use of.
Summary
Point2Listregions (e.g. separate head/body/feet hitboxes), while maintaining backward compatibility with the single-region APIRotatableHitBoxintoHitBoxand adds JSON serialization support (with optional gzip compression)sprite_multi_hitboxexample and expanded test coverageTest plan
tests/unit/hitbox/test_hitbox.py)sprite_multi_hitboxexample🤖 Generated with Claude Code