【发布时间】:2016-12-21 15:57:47
【问题描述】:
我正在尝试使用 Phaser.io 制作一个小型 HTM5 游戏。
我有一个无法解决的小问题。
在我的 MainClass(游戏)中,我只想创建一个循环,该循环将创建一个新对象(一枚硬币)并将其添加到一个组中。
但我不知道为什么,我调用的那个小函数永远不会启动。
这是我的代码:
create() {
//coins group
this.coins = this.game.add.group;
//set background
this.game.stage.backgroundColor = "#00F6FA";
//load the map
this.map = this.game.add.tilemap('level', 195, 195, 2, 4);
this.map.addTilesetImage('free-2d-game-tiles-post-pic-1', 'tiles');
//load collision layer
this.layer = this.map.createLayer('collision');
//this.layer.debug = true;
//make the layer collide
this.map.setCollisionBetween(8, 9, true, this.layer.index, true);
//enable physics
this.game.physics.startSystem(Phaser.Physics.ARCADE);
//set the player
this.player = new Player(this.game, 0, 0);
this.game.time.events.repeat(Phaser.Timer.SECOND * 2, 10, this.createCoin, this);
}
就在后面:
createCoin(): void {
/*
generate a coin
*/
console.log('test');
}
很简单,但什么都不会发生。
你看到我想念什么了吗?
编辑 1:
好的,这是我在 Github 上的代码:
https://github.com/c4n4r/coinFall/blob/master/JS/app.ts
我还是不知道怎么了……
【问题讨论】:
标签: html typescript phaser-framework