pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.71k stars 330 forks source link

Hitbox generation doesn't support multiple hitboxes from one texture #2457

Open Dwang-ML opened 4 days ago

Dwang-ML commented 4 days ago

Bug Report

Hitboxes can not be seperated, meaning multiple hitboxes cannot be be generated from one texture.

System Info

Arcade 3.0.0.dev39

vendor: Apple renderer: Apple M2 version: (4, 1) python: 3.12.3 (v3.12.3:f6650f9ad7, Apr 9 2024, 08:18:47) [Clang 13.0.0 (clang-1300.0.29.30)] platform: darwin pyglet version: 2.1.rc1 PIL version: 11.0.0

Actual behavior:

ML 2024-11-17 at 7 11 22 PM

Let everything in RED be the image and everything that is not red be transparent. If the hitbox is calculated for a png like this, arcade draws the hitbox as shown in blue.

Expected behavior:

ML 2024-11-17 at 7 11 56 PM

Instead of the behavior shown in Actuall behavior, there should be a option to seperate hitboxes as shown in the image above.

Steps to reproduce/example code:

Simply have a png with a few seperate shapes and let arcade calculate the hitbox.

pushfoo commented 4 days ago

TL;DR: Splitting textures into multiple hitboxes seems like a new feature worth considering

To my understanding, Arcade's API assumes the following:

  1. Textures will each have one contiguous sprite element
  2. There will be one contiguous unscaled hitbox per each texture
  3. Sprites have one current texture and one scaled hitbox
  4. Most users will use smaller convex sprites or grid-based games

The last item is important. From what you said on Discord earlier, you had perf drop when using detailed hitboxes:

oh and the fps of the game dropped from 60 -> 30

If the terrain is non-moving, try enabling spatial hashing by passing spatial_hashing=True when creating the terrain list. Since your sprites are large and detailed, you will need to be extra careful about making sure you don't move your sprites. Otherwise, it seems likely you'll have big perf drops.