我是 Phaser 的菜鸟,正在开发 Flappy Bird。我尝试做一个无限大的地面,我试过 tilePosition,但它不起作用。
var ground;
function preload(){
game.load.image('ground', '/assets/groud.png');
}
function create(){
ground = game.add.tileSprite(0, 480, 'ground');
}
function update(){
ground.tilePosition.x -= 1;
}
但它不起作用。有人可以帮助我吗?
最佳答案
constructor for TileSprite需要参数 x, y, width, height, key
(和 frame
,但这只适用于 spritesheets,不适用于 image
)。
所以我认为您忘记了宽度和高度参数,导致 Phaser 将“地面”视为宽度。这可能会在 JavaScript 控制台上引发一条错误消息。在 Chrome 中按 CTRL+Shift+J 或在 FireFox 中按 F12,然后检查控制台是否有任何消息。
此外,我不知道您使用的是什么分辨率,但参数 480
是 y 位置,这可能会导致 TileSprite 位于屏幕下方,因此它不可见?
也许试试这个:
function create(){
ground = game.add.tileSprite(0, 100, game.width, 50, 'ground');
}
关于javascript - Phaser-如何制作无限大地?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47820658/