Skip to content

Touch input is off on Y axis on WASM export #10694

@jaminhaber

Description

@jaminhaber

Bevy version

[dependencies]
bevy = "0.12.0"
bevy_embedded_assets = "0.9.1"
rand = "0.8.5"
wasm-bindgen = "0.2.88"

Relevant system information

  • the Rust version you're using (you can get this by running cargo --version)
    • cargo 1.73.0 (9c4383fb5 2023-08-26)
  • the operating system or browser used, including its version
    • MacOS Sonoma 14.1.1 (23B81)
  • Browser: Chrome

What you did

I get the position of a touch like this:

 let just_pressed = touches.iter().find(|t| touches.just_pressed(t.id()));
 let touch_pos =  just_pressed.unwrap().position();
 println!("touch at ({},{})", touch_pos.x, touch_pos.y);

then build using this script

APP_NAME="sokoban"
cargo build --release --target wasm32-unknown-unknown
wasm-bindgen --out-dir 'out/webgl' --target web "target/wasm32-unknown-unknown/release/${APP_NAME}.wasm"
open "out/webgl"

What went wrong

touching the top right of the screen (640x480) produces the coordinates (19,218)

You can experience this by trying to press the buttons on the live version of the game on my website while using the mobile emulator for chrome.... You will have to tap about half way up the screen in order to press the buttons on the menus.

Additional information

image

The coordinates are off by about half the screen height, maybe it has to do with the grid originating from the middle of the screen rather than the top?

Screenshot 2023-11-22 at 12 45 22 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreA-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions