Hello,
I’m doing the phaser course and I’m stuck at getting user input through the isDown function: on safari, this function is called every frame once I press a key and never stops. It seems to get stuck in an infinite loop. The same code works fine on Chrome. Any idea as to what might be causing that and how to fix it? Here is my code:
<html>
<head>
<script src="//cdn.jsdelivr.net/npm/phaser@3.24.1/dist/phaser.js"></script>
</head>
<body>
<p>Hello there</p>
<script>
const gameState = {};
function preload() {
this.load.image(
"codey",
"https://content.codecademy.com/courses/learn-phaser/codey.png"
);
}
function create() {
gameState.codey = this.add.sprite(150, 200, "codey");
// Set cursor keys here!
gameState.cursors = this.input.keyboard.createCursorKeys();
}
function update() {
// Update based on keypress here!
if (gameState.cursors.left.isDown) {
gameState.codey.x -= 1;
console.log("Key is down");
} else if (gameState.cursors.right.isDown) {
gameState.codey.x += 1;
console.log("Key is down");
} else if (gameState.cursors.up.isDown) {
gameState.codey.y -= 1;
console.log("Key is down");
} else if (gameState.cursors.down.isDown) {
gameState.codey.y += 1;
console.log("Key is down");
}
}
const config = {
type: Phaser.AUTO,
width: 400,
height: 500,
backgroundColor: "#5f2a55",
scene: {
preload,
create,
update,
},
};
const game = new Phaser.Game(config);
</script>
</body>
</html>
And here is the behavior on Safari: