Invalid pointer world position when camera/world scale is not 1 or world rotation is not 0

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

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

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

Đánh giá

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

Hướng nghiên cứu

The issue provides a JavaScript example using game.input.mousePointer, game.camera, and game.world, but names no source files or tests. Start by tracing how pointer worldX and worldY are calculated and how camera and world transforms are applied. Done means pointer world position stays correct when world scale or rotation changes, including the cases shown in the example.

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

Mô tả

needs code example

If world scale is not 1 or rotation is not 0 pointer world position will be invalid.

Sample code:

var sprite;

function preload() {
    game.load.baseURL = 'http://examples.phaser.io/assets/';
    game.load.crossOrigin = 'anonymous';
    game.load.image('phaser', 'sprites/phaser-dude.png');
}

function create() {
    game.world.position.set(100,100);
    if (1)
    {
        game.world.scale.set(0.5,0.5);
    }
    if (1)
    {
        game.world.rotation = Math.PI * 45 / 180;
    }
    sprite = game.add.sprite(0, 0, 'phaser');
    sprite.anchor.set(0.5, 0.5);
}

function update() {
    var pointer = game.input.mousePointer;
    sprite.x = pointer.worldX;
    sprite.y = pointer.worldY;
}

Temporary workaround:

var sprite;

function preload() {
    game.load.baseURL = 'http://examples.phaser.io/assets/';
    game.load.crossOrigin = 'anonymous';
    game.load.image('phaser', 'sprites/phaser-dude.png');
}

function create() {
    game.world.position.set(1000,1000);
    if (1)
    {
        game.world.scale.set(0.5,0.5);
    }
    if (1)
    {
        game.world.rotation = Math.PI * 15 / 180;
    }
    sprite = game.add.sprite(0, 0, 'phaser');
    sprite.anchor.set(0.5, 0.5);
}

function update() {
    var pointer = game.input.mousePointer;
    var camera = game.camera;
    var world = game.world;
    var rotation = -world.rotation;
    var sin = Math.sin(rotation);
    var cos = Math.cos(rotation);
    var tmpX = (pointer.x + camera.position.x) / camera.scale.x;
    var tmpY = (pointer.y + camera.position.y) / camera.scale.y;
    var worldX = tmpX * cos - tmpY * sin;
    var worldY = tmpX * sin + tmpY * cos;
    sprite.x = worldX;
    sprite.y = worldY;
}
Ngôn ngữ chính
JavaScript
Star
1.4k
Fork
485
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
9

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-ce

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

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.