Skip to content

Commit

Permalink
Fixed check_collision_with_point function
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan committed Oct 18, 2024
1 parent 3e45921 commit 5284084
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/extension/spx_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,20 @@ GdBool SpxSprite::check_collision(SpxSprite *other, GdBool is_src_trigger, GdBoo
}

GdBool SpxSprite::check_collision_with_point(GdVec2 point, GdBool is_trigger) {
auto pos = this->get_position();
auto this_shape = is_trigger ? this->trigger2d : this->collider2d;
if (!this_shape->get_shape().is_valid()) {
return false;
}
return this_shape->get_shape()->_edit_is_selected_on_click(point, 0);

Ref<CircleShape2D> point_shape;
point_shape.instantiate();
point_shape->set_radius(3);

Transform2D point_transform(0, point);
Transform2D sprite_transform = get_global_transform();
bool is_colliding = this_shape->get_shape()->collide(sprite_transform, point_shape, point_transform);
return is_colliding;
}
void SpxSprite::set_render_scale(GdVec2 scale) {
anim2d->set_scale(scale);
Expand Down
1 change: 1 addition & 0 deletions core/extension/spx_sprite_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ GdBool SpxSpriteMgr::check_collision(GdObj obj, GdObj target, GdBool is_src_trig

GdBool SpxSpriteMgr::check_collision_with_point(GdObj obj, GdVec2 point, GdBool is_trigger) {
check_and_get_sprite_r(false)
point.y = - point.y;
return sprite->check_collision_with_point(point, is_trigger);
}

Expand Down

0 comments on commit 5284084

Please sign in to comment.