How can I make an infinite side scrolling background in Phaserjs?

↘锁芯ラ 提交于 2019-12-03 18:57:37

问题


I'm using phaser.js to make a game and I cannot find any tutorials on how to make the background scroll infinitely. I'd like the background to tile/repeat sideways, and infinitely as the character moves right.

I am currently using a camera and having the camera follow the character.

Here's my idea about how to do this: Check the position of the camera constantly in update(), and then move it to the beginning of gameplay (the very left) along with the character at that time. I think that this would probably not be a smooth transition though, so I'm wondering if there is a better way to do it.


回答1:


This can be done with a tile sprite and by moving "tilePosition":

var bgtile;

function preload () {
   game.load.image('bgtile', 'bgtile.jpg');
}

function create () {
   bgtile = game.add.tileSprite(0, 0, game.stage.bounds.width, game.cache.getImage('bgtile').height, 'bgtile');
}

function update () {
   bgtile.tilePosition.x -= 1;
}


来源:https://stackoverflow.com/questions/21669312/how-can-i-make-an-infinite-side-scrolling-background-in-phaserjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!