Zendrael Posted November 19, 2015 Share Posted November 19, 2015 Hi! I'm new to phaser and i'm having some problems with my backgrounds not repeating (I don't want it to move, just repeat on X). Attached is what is happening. My code so far haspreload : function(){ ... GAME.load.image('backgrounds', 'img/backgrounds.png'); ...},create : function() { ... BACKGROUND = GAME.add.tileSprite(0, -16, 160, 144, 'backgrounds'); ...}Do I have to programatically repeat the background on update? Thanks Link to comment Share on other sites More sharing options...
Skeptron Posted November 19, 2015 Share Posted November 19, 2015 Yes, you do have to repeat the background manually. This isn't done by default. Link to comment Share on other sites More sharing options...
Zendrael Posted November 19, 2015 Author Share Posted November 19, 2015 Yes, you do have to repeat the background manually. This isn't done by default.Thanks! So, it's better to use the render or update function to do that? And, is there a way to use a spritesheet with various sprite sizes without using an Atlas file? Link to comment Share on other sites More sharing options...
jmp909 Posted November 19, 2015 Share Posted November 19, 2015 you don't need to repeat a TileSprite manually, just set it to the width/height of your game (or whatever height you need)A TileSprite is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so. Please note that TileSprites, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.if you're scrolling you can change tilePosition.x as necessary http://phaser.io/sandbox/GpbGgKwT/play Link to comment Share on other sites More sharing options...
Zendrael Posted November 19, 2015 Author Share Posted November 19, 2015 Hi jmp909! So, a TileSprite just repeats an image but not load part of an image, right? If I have one Spritesheet with all my backgrounds, I have to convert each one on single separate images? Thanks! Link to comment Share on other sites More sharing options...
jmp909 Posted November 19, 2015 Share Posted November 19, 2015 looking at your design do you think you might benefit from using an actual Tilemap with eg 32x32 or 64x64 blocks rather than just one big image? you have a lot of repeated patterns there anyway unless you're needing to use all of the backgrounds in one level, I wouldn't necessarily put them all on one spritesheet. but TileSprite accepts a 'frame' parameter so you can just use that to get the relevant image from your spritesheet. new TileSprite(game, x, y, width, height, key, frame)frame: If this TileSprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.http://phaser.io/docs/2.4.4/Phaser.TileSprite.html Link to comment Share on other sites More sharing options...
Zendrael Posted November 19, 2015 Author Share Posted November 19, 2015 Thanks! I will try to play around with this! Link to comment Share on other sites More sharing options...
Recommended Posts