Jump to content

Tiled Background


Zendrael
 Share

Recommended Posts

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 has

preload : 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

 

 

 

post-17382-0-53644800-1447932336.png

Link to comment
Share on other sites

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...