Javascript 未捕获类型错误:无法读取属性';圆圈';在Phaser JS项目中。不能使用函数
这里是初学者。 我想编一个小游戏。作为测试,我想让圆圈在屏幕上每隔一秒钟随机出现一次。如果你点击它们,它们就会消失 对于屏幕上的外观,我想使用一秒钟的间隔。为此,我创建了一个gamplay函数。但是在这个函数中,我不能使用特定于相位器的函数。我不能创建文本或形状 我的问题是:为什么会这样?我不明白什么?我该如何解决这个问题呢 谢谢你的帮助 来自德国的问候 (对不起,输入和语法错误) 主要游戏场景Javascript 未捕获类型错误:无法读取属性';圆圈';在Phaser JS项目中。不能使用函数,javascript,phaser-framework,Javascript,Phaser Framework,这里是初学者。 我想编一个小游戏。作为测试,我想让圆圈在屏幕上每隔一秒钟随机出现一次。如果你点击它们,它们就会消失 对于屏幕上的外观,我想使用一秒钟的间隔。为此,我创建了一个gamplay函数。但是在这个函数中,我不能使用特定于相位器的函数。我不能创建文本或形状 我的问题是:为什么会这样?我不明白什么?我该如何解决这个问题呢 谢谢你的帮助 来自德国的问候 (对不起,输入和语法错误) 主要游戏场景 constructor(){ super({ key: 'GameScene'
constructor(){
super({ key: 'GameScene' })
}
preload(){
}
//---------------------------------------------------------------------------------------------------------------------
create(){
const startingMinutes = 1;
let time = startingMinutes * 60; //Zeit in Sekunden
//Test Here i can still use Phaser funktions
gameState.texttest = this.add.text(150, 250, 'This is working', { fill: '#000000', fontSize: '20px' });
setInterval(updatecountdown, 1000);
function updatecountdown(){
//Countdown
if(time > 0){
//console.log("Time: " + time);
const minutes = Math.floor(time / 60); //Math floor rundet
let seconds = time % 60;
console.log("minuten: " + minutes);
console.log("sekunden: " + seconds);
time--;
}else{
gameState.gameOn = false;
}
}
setInterval(gameplay, 1000);
function gameplay(){
if(gameState.gameOn === true){
let Xvar = Math.floor(Math.random() * 480);
console.log(Xvar);
let Yvar = Math.floor(Math.floor(Math.random()*380));
console.log(Yvar);
gameState.circle1 = this.add.circle(Xvar, Yvar, 20, 0x98fb98 );
gameState.circle1.setInteractive();
gameState.circle1.on('pointerup', function(){
gameState.circle1.destroy();
})
}else{
gameState.endtext = this.add.text(150, 250, 'The End', {fill: '#000000', fontSize: '20px'});
}
}
}
//---------------------------------------------------------------------------------------------------------------------------
update(){
}
}
配置
};
const config = {
type: Phaser.AUTO,
width: 500,
height: 400,
backgroundColor: "#b0e0e6",
scene: [StartScene, GameScene, EndScene]
};
gameState.gameOn = true;
const game = new Phaser.Game(config);
``
上下文丢失。在javascript回调中,我们得到的是当前调用上下文。 当您使用setInterval时,setInterval中的函数将用作
此
非相位器。场景
尝试使用setInterval,以便:
setInterval(gameplay.bind(this), 1000);
上下文丢失。在javascript回调中,我们得到的是当前调用上下文。 当您使用setInterval时,setInterval中的函数将用作
此
非相位器。场景
尝试使用setInterval,以便:
setInterval(gameplay.bind(this), 1000);