Skip to content

Commit d7d8bc1

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

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,27 @@ 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+
Some(root) => root
750+
.loader_info()
751+
.as_ref()
752+
.and_then(|loader_info| loader_info.as_loader_info_object())
753+
.and_then(|loader_info_obj| loader_info_obj.loader())
754+
.is_none(),
755+
None => false,
756+
};
757+
748758
let local = Point::from_pixels(x, y);
749-
let global = dobj
750-
.avm2_root()
751-
.map_or(local, |root| root.local_to_global(local));
759+
let global = if is_player_root {
760+
// If this root is the root of the player, match avm1 hitTest behavior and treat the
761+
// input as root-relative coordinates (even if no longer a direct child of the stage)
762+
avm_root.unwrap().local_to_global(local)
763+
} else {
764+
// Otherwise, the docs are truthful and the coordinates are relative to the stage
765+
// (aka nothing for us to do)
766+
local
767+
};
752768

753769
if shape_flag {
754770
if !dobj.is_on_stage(activation.context) {

0 commit comments

Comments
 (0)