Loupax Posted March 16, 2014 Share Posted March 16, 2014 Hello everyone! I am Loupax and this is my first post here I am trying to create an infinite side scroller in Phaser 2.0, so my first thought was to do the following:var preload = function(){ game.load.image('hero', 'assets/images/angry-robot-nerd.png'); game.load.image('background', 'assets/images/background.jpg'); };var create = function(){ // Set the game to be infinetly wide. The camera follows the hero indefinetely in the x axis as expected game.world.setBounds(0, 0, Infinity, game.height); // Try 1) Set the tile sprites' width equal to the width of the stage bounds // This results to a background as wide as the stage itself game.add.tileSprite(0, 0, game.stage.bounds.width, game.height, 'background'); // Try 2) Set the tile sprites' width to Infinity. // This results in a black background. No error is raised game.add.tileSprite(0, 0, Infinity, game.height, 'background'); hero = initializeHero(); game.camera.follow(hero); };Is Infinity a valid value for the dimentions of the game.world.setBounds method to begin with?Is it possible to make the Infinity valid for the width of the tile sprite? Link to comment Share on other sites More sharing options...
rich Posted March 16, 2014 Share Posted March 16, 2014 You absolutely don't want to do it like this! Your tileSprite doesn't need to be any wider than your game width (probably around 800px?) All you need do is fix it to the camera so it doesn't scroll off the screen, and then scroll is using either autoScroll or tilePosition. The world can't have an infinity value for its bounds either I'm afraid. You need to re-think your approach to how you're going to do this. For a side-scrolling shooter you probably don't need much of a world size at all, as the player would remain fixed in it and you'd just scroll the baddies past him (and other scenery objects). So the actual world width is most likely quite tiny. Link to comment Share on other sites More sharing options...
Loupax Posted March 16, 2014 Author Share Posted March 16, 2014 For a side-scrolling shooter you probably don't need much of a world size at all, as the player would remain fixed in it and you'd just scroll the baddies past him (and other scenery objects). So the actual world width is most likely quite tiny. I thought that was being handled automatically by the camera functionality... Unless you mean that no camera is necessary in that use case. I'll think about it, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts