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

Selection hitbox messed up on sprite with repeated texture #60141

Closed
Ev01 opened this issue Apr 11, 2022 · 5 comments · Fixed by #78566
Closed

Selection hitbox messed up on sprite with repeated texture #60141

Ev01 opened this issue Apr 11, 2022 · 5 comments · Fixed by #78566

Comments

@Ev01
Copy link
Contributor

Ev01 commented Apr 11, 2022

Godot version

4.0 alpha6

System information

Windows 10, Vulkan Desktop

Issue description

When I create a sprite with a repeated texture, clicking on the sprite in some areas does not select it.

godot_select_bug

Clicking on any part of the sprite I've highlighted in yellow behaves normally and selects the sprite as expected, but clicking on any other part of the sprite behaves as if I clicked on empty space and deselects the sprite.

Steps to reproduce

  1. Create a sprite with repeat set to enabled or mirror
  2. Set a TextureRegion on the sprite that is larger than the sprite
  3. Click on any part of the sprite directly below or to the right of the original. This will select it as normal.
  4. Click on any part of the sprite that is not directly below or to the right of the original. This will deselect it instead of selecting it.

Minimal reproduction project

Selection Bug - 4.0 alpha6.zip

@Calinou
Copy link
Member

Calinou commented Apr 11, 2022

Does it work on Godot 3.4.4?

@sriramun
Copy link
Contributor

Does it work on Godot 3.4.4?

No — the repeat feature was introduced in 4.0 if I'm not wrong.

@Calinou Calinou added this to the 4.0 milestone Apr 11, 2022
@akien-mga akien-mga modified the milestones: 4.0, 4.1 Feb 17, 2023
@akien-mga
Copy link
Member

akien-mga commented Jun 22, 2023

Confirmed still reproducible in 4.1 beta 3. CC @kleonc @KoBeWi

Note: To open the MRP successfully, make sure to first delete the .godot folder, as the imported WebP is incompatible with 4.0-stable and later.

@akien-mga akien-mga modified the milestones: 4.1, 4.x Jun 22, 2023
@kleonc
Copy link
Member

kleonc commented Jun 22, 2023

The cause is here:

// TODO: This need to be obtained from CanvasItem new repeat mode (but it needs to guess it from hierarchy, need to add a function for that).
bool is_repeat = false;
bool is_mirrored_repeat = false;
if (is_repeat) {
int mirror_x = 0;
int mirror_y = 0;
if (is_mirrored_repeat) {
mirror_x = (int)(q.x / texture->get_size().width);
mirror_y = (int)(q.y / texture->get_size().height);
}
q.x = Math::fmod(q.x, texture->get_size().width);
q.y = Math::fmod(q.y, texture->get_size().height);
if (mirror_x % 2 == 1) {
q.x = texture->get_size().width - q.x - 1;
}
if (mirror_y % 2 == 1) {
q.y = texture->get_size().height - q.y - 1;
}
} else {
q.x = MIN(q.x, texture->get_size().width - 1);
q.y = MIN(q.y, texture->get_size().height - 1);
}

Currently it's always executing the else block.

@kleonc
Copy link
Member

kleonc commented Jun 22, 2023

Does it work on Godot 3.4.4?

And for reference it works fine in 3.x, as texture repeat flags are checked accordingly in there:

godot/scene/2d/sprite.cpp

Lines 327 to 328 in 7cfd984

bool is_repeat = texture->get_flags() & Texture::FLAG_REPEAT;
bool is_mirrored_repeat = texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants