gpt4 book ai didi

javascript - 如何使用移相器找到鼠标位置 x/y

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:33:09 26 4
gpt4 key购买 nike

我遇到了问题,当他们点击图像时试图显示鼠标位置 x/y,我正在使用移相器提供的点击和图像示例之一。

这是代码

var game = new Phaser.Game(800, 500, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });

var text;
var counter = 0;

function preload () {

// You can fill the preloader with as many assets as your game requires

// Here we are loading an image. The first parameter is the unique
// string by which we'll identify the image later in our code.

// The second parameter is the URL of the image (relative)
game.load.image('Happy-face', 'happy.png');

}

function create() {

// This creates a simple sprite that is using our loaded image and
// displays it on-screen and assign it to a variable
var image = game.add.sprite(game.world.centerX, game.world.centerY, 'Happy-face');

// Moves the image anchor to the middle, so it centers inside the game properly
image.anchor.set(0.5);

// Enables all kind of input actions on this image (click, etc)
image.inputEnabled = true;
this.position = new Phaser.Point();
text = game.add.text(250, 16, '', { fill: '#ffffff' });

image.events.onInputDown.add(listener, this);

}

function listener () {

counter++;
text.text = "Position x/y " + counter + "!";


}

最佳答案

如果你想要输入的x和y位置

game.input.x;
game.input.y;

如果你特别想要鼠标

game.input.mousePointer.x;
game.input.mousePointer.y;

监听函数会像

function listener () {

counter++;
text.text = game.input.mousePointer.x +"/"+game.input.mousePointer.y + counter + "!";


}

关于javascript - 如何使用移相器找到鼠标位置 x/y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28104605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com