Hello, is it anyhow possible to periodically call a function while pointerdown?
I am currently moving the camera on pointerdown and therefore while pointer is down the world position of the pointer moves but it is not updating when calling periodically game.input.activePointer.worldX
What I got (where move is just moving the camera):
this.on("pointerdown", (event: Phaser.Input.Pointer) => {
move(event); // call every 500ms while pointerdown
this.on("pointermove", move);
});
this.on("pointerup", () => this.off("pointermove", move));
Ok, add this listener to get the pointer x, y position(not sure about event.World, add a console.log to detect the good value) and use MoveX as current pointer position
The moving from pointerdown and pointermove works fine, but when button is pressed (pointerdown) then it only fires one event and stops (pointermove and up works).
What I want:
pointerdown started => move
after 500ms pointer is still not up => move
goto 2.
Maybe I have to emit manually more pointerdown events which are coded every 500ms?
The problem is I dont know how to get the updated Phaser.Input.Pointer
It looks interesting, solves another âproblemâ so I donât have to on and off pointermove and just check if pointer is down.
Unfortunately it doesnât solve the pointerdown problem.
If the camera have the position (0, 0) and I press the pointer (on world position (50, 50)) then the camera position is set to (50, 50) but the pointer is now at (100, 100), pressing it again would work, camera (100, 100) ⌠pointer (150, 150).
What I want to achieve now is making this with only one pointerdown event and while it is down it updates the camera with the actual pointer world positions.
Maybe just to explain a little bit more I am moving the camera from start to end with elapsedTime so therefore adding every 500ms the (50, 50) does not work and I need the actual world position from the pointer.
When pointerdown is fired the pointer itself is not updated so therefore while it is pressed and not moved this.input.pointer will be the same.
I think it is not possible with pointer events itself to solve the problem.
Probably have to make it a little bit hacky something like that:
this.on("pointerdown", (event) => {
const startX = camera.x;
const startY = camera.y;
move(event);
const doEvery500Ms = () => {
const elapsedX = event.worldX - startX;
const elapsedY = event.worldY - startY;
event.worldX += elapsedX;
event.worldY += elapsedY;
...update startx and y with actual camera pos
move(event);
};
})
thatâs why i suggested you to use the update loop to always get the pointer world position up to date, and so you can use this.moveX and this.moveY in your âpointerdownâ eventListener
The pointer is not updated on the update loop, it looks that it works like this:
pointerdown -> update pointer
move camera -> but pointer on next update will be still the same
only after pointerup the pointer gets the new position
Codepen - custom example
Not exactly how I wanted it to make but it should be clearly demonstrate that if you press the button then the camera position will be updated but the world is only updated after you make another pointer event.