Incorrect pointer worldX/Y when polling.

Đang mở
#7,411 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, typescript
Lĩnh vực
game-dev

Hướng nghiên cứu

Run the pasted scene and compare the two log lines to confirm that only the polled worldX/worldY are missing the camera scroll. Then follow how the Pointer's worldX/worldY properties get set on pointer movement versus what the pointerdown event path does (it applies the camera transform), and make the polled values use the same camera-aware conversion. Done means both logs agree for a scrolled camera, checked with this.cameras.main.setScroll(...) as in the example.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version

  • Phaser Version: 4.2.1
  • Operating system: any

Description

Pointer world coordinates are incorrect when polling, but correct when listening to event. The difference is, that when polling, camera scrollX/Y is not counted in.

Example Test Code

This is minimal test code. It moves the center of the world into the screen center. Then, when you click on screen it will log worldX/Y from event and also do a single poll in an update.

export class Test extends Phaser.Scene {

    private _logPosition: boolean = false;

    public create() {

        // focus on center
        this.cameras.main.setScroll(-this.scale.width / 2, -this.scale.height / 2);

        // hang on event
        this.input.on(Phaser.Input.Events.POINTER_DOWN, (pointer: Phaser.Input.Pointer) => {
            console.log(`Event: pointer id: ${pointer.id}, worldX: ${pointer.worldX}, worldY: ${pointer.worldY}`);
            this._logPosition = true;
        });
    }

    public override update(): void {

        // poll
        if (this._logPosition) {
            console.log(`Polling: pointer id: ${this.input.activePointer.id}, worldX: ${this.input.activePointer.worldX}, worldY: ${this.input.activePointer.worldY}`);
            this._logPosition = false;
        }
    }
}

If you click more or less into the center of the screen, you will get something close to this (depends on game size - mine is 800x1280. The world center is moved into the screen center, so the difference is 400 for x and 640 for y):

Event: pointer id: 0, worldX: -5.774434713492724, worldY: 10.586466165413526
Polling: pointer id: 0, worldX: 394.5864661654135, worldY: 650.5864661654135

The first line is from event (close to center). The second one is relative from top left corner (not taking into account camera.scrollX/Y).

Ngôn ngữ chính
JavaScript
Star
40.7k
Fork
7.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phaserjs/phaser

Tất cả issue của phaserjs/phaser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.