Skip to content

Commit b351895

Browse files
committed
avm2: hitTestPoint should only use local coordinates for the player root
1 parent 3744731 commit b351895

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
@@ -743,11 +743,28 @@ pub fn hit_test_point<'gc>(
743743
let y = args.get_f64(activation, 1)?;
744744
let shape_flag = args.get_bool(2);
745745

746-
// Transform the coordinates from root to world space.
746+
let avm_root = dobj.avm2_root();
747+
let is_player_root = match avm_root {
748+
// We can detect the root of the player by the fact that it doesn't have a loader.
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+
747758
let local = Point::from_pixels(x, y);
748-
let global = dobj
749-
.avm2_root()
750-
.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+
};
751768

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

0 commit comments

Comments
 (0)