Jump to content

Looping background image?


iShellz
 Share

Recommended Posts

Something like this is how tileSprite works, you use the tilePosition x/y coordinates to move the background which is automatically tiled. The important thing to keep in mind is the image you are using HAS to be in the power of 2 (eg. 256x256, 512x512x 1024x1024). 

 

function preload() {

 

game.load.image("background", "background.png");

 

},

 

function create() {

 

var background = game.add.tileSprite(0, 0, 500, 500, "background");

 

},

 

function update() {

 

background.tilePosition.x = 0.5;

 

},

Link to comment
Share on other sites

Does the image has to be bigger than the canvas or it doesn't matter?

 

I have a 1024x1024 image background, my canvas is w: 400, h: 600 and I have this set up but can't see any movement effect. What am I missing here?

  create: function() {    this.bg = game.add.tileSprite(0, 0, 400, 600, 'bg');
  update: function() {    this.bg.tilePosition.x = 0.5;
Link to comment
Share on other sites

 

Does the image has to be bigger than the canvas or it doesn't matter?

 

I have a 1024x1024 image background, my canvas is w: 400, h: 600 and I have this set up but can't see any movement effect. What am I missing here?

  create: function() {    this.bg = game.add.tileSprite(0, 0, 400, 600, 'bg');
  update: function() {    this.bg.tilePosition.x = 0.5;

I guess the first step would be where is the part of your background that is textured to loop while it moves ?

 

 

jbiOYHKS2QwRKq.pngThis one would loop no matter where the camera is

 

jbrY2GeNa0ZK2n.pngthis may not because you wont be able to see the part that is moving 

Link to comment
Share on other sites

Yes, but there are two backgrounds there. I put one background then the other? And I put a piece of what I want to move and set the tilePosition and it goes to a loop the whole time? Obviously I don't get how this works. :S

 

EDIT: I GOT IT! :)

It was suppose to be:

this.bg.tilePosition.x += 1;

With emphasis on += :)

Link to comment
Share on other sites

  • 4 years later...

is there a reason why tiled images needs to be power of 2? while regular sprites can be in any size? is tiled sprites using a special feature that needs power of 2? if it is, then i guess i just have to make my own tiled sprites using regular sprites and manually move them etc etc

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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