【发布时间】:2019-04-10 03:43:59
【问题描述】:
我正在编写一个游戏,这是其中的一部分。我希望程序循环浏览我上传的精灵运行的不同图片。我创建了一个变量,让程序知道正在运行的角色屏幕上显示的是哪张图片。程序无法识别它是一个正在声明的变量。我只是在使用 Javascript 时犯了一个简单的错误吗?
我试图在我的代码周围移动变量声明,并在其中放入不同的东西。似乎没有任何效果。
class Example1 extends Phaser.Scene {
constructor() {
super({key: "Example1"});
}
//variable for the current running stance which does not work
var playerBoard = 1;
preload() {
this.load.image('Background', 'assets/Background.jpg');
this.load.image('4 JUMP_000', 'assets/4 JUMP_000.png');
let run1 = this.load.image('3 RUN_000', 'assets/3 RUN_000.png');
let run2 = this.load.image('3 RUN_001', 'assets/3 RUN_001.png');
let run3 = this.load.image('3 RUN_002', 'assets/3 RUN_002.png');
let run4 = this.load.image('3 RUN_003', 'assets/3 RUN_003.png');
let run5 = this.load.image('3 RUN_004', 'assets/3 RUN_004.png');
}
/*another variable to help return to the first running stance when the sprite stops running*/
let runningStance = run1;
//function that switches the running stances
runningScene(x,y){
if(this.input.keyboard.on("keyDown_D")){
while(this.input.keyboard.on("keyDown_D")) {
if (this.playerBoard = 1) {
this.playerBoard1 = 2;
this.image = this.add.image(this.image.x, this.image.y, '3 RUN_001');
runningStance = run2;
run1.visable = false;
}
程序中的一些代码不包括在内,因为它会占用太多空间。不起作用的是变量的声明,因为它不允许 if 函数正常工作。我安装了移相器,你可以在代码中参考。输出应该隐藏起始图片并显示序列中的下一张,这将是 run2。
【问题讨论】:
-
runningScene在哪里调用/传递? -
runningScene 可能未声明,顺便说一句,run1 和 run2 也未在任何地方声明
标签: javascript phaser-framework