Skip to content

Commit e9b9a5a

Browse files
committed
avm2: hitTestPoint should only use local coordinates for the player root
1 parent 5ed3a49 commit e9b9a5a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

core/src/avm2/globals/flash/display/display_object.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,28 @@ pub fn hit_test_point<'gc>(
744744
let y = args.get_f64(activation, 1)?;
745745
let shape_flag = args.get_bool(2);
746746

747-
// Transform the coordinates from root to world space.
747+
let avm_root = dobj.avm2_root();
748+
let is_player_root = match avm_root {
749+
// We can detect the root of the player by the fact that it doesn't have a loader.
750+
Some(root) => root
751+
.loader_info()
752+
.as_ref()
753+
.and_then(|loader_info| loader_info.as_loader_info_object())
754+
.and_then(|loader_info_obj| loader_info_obj.loader())
755+
.is_none(),
756+
None => false,
757+
};
758+
748759
let local = Point::from_pixels(x, y);
749-
let global = dobj
750-
.avm2_root()
751-
.map_or(local, |root| root.local_to_global(local));
760+
let global = if is_player_root {
761+
// If this root is the root of the player, match avm1 hitTest behavior and treat the
762+
// input as root-relative coordinates (even if no longer a direct child of the stage)
763+
avm_root.unwrap().local_to_global(local)
764+
} else {
765+
// Otherwise, the docs are truthful and the coordinates are relative to the stage
766+
// (aka nothing for us to do)
767+
local
768+
};
752769

753770
if shape_flag {
754771
if !dobj.is_on_stage(activation.context) {

0 commit comments

Comments
 (0)