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

后端 未结 1 781
夕颜
夕颜 2020-12-25 12:45

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 in

相关标签:
1条回答
  • 2020-12-25 13:26

    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;
    }
    
    0 讨论(0)
提交回复
热议问题