a better way to do endless scrolling background?

aussiefazaussiefaz Member, PRO Posts: 86

Hi guys, I 've been struggling to get this working right for the last two days.

I've read through a lot of posts about scrolling backgrounds, and also tested out different sample methods, and for some reason none of them worked for me. not sure what I was doing wrong.

I finally got this one to work this morning, when I was able to ask what I was doing wrong, but thought I'd still ask if there is a better way to do this just in case the way I've done it is not the best way.

First Ive got my game setup for ipad landscape.

Ive set the Scene attribute size to 2048wide x 768 high and wrap X

On the scene layer I have the Background set to scrollable checked.

Then I've gone in to add my background actor and named it background

Set the size to 1024 wide x 768 high and made sure it's movable

Next the first behaviour I added was Move, with direction of 180 and speed of 140, relative to actor and type of additive.

Then I've added in a rule, set when All conditions are valid, Attribute self.Position.X is < less than -self.Size.Width/2

Then added the change attribute for this rule to self.Position.X to self.Position.X+self.Size.Width+game.Display Size.Width

Once I did that, I went back to the scene. Dragged first instance of Background onto the main viewable screen, then dragged second instance of Background to the very right hand edge of the first Background.

This all works seamlessly for me now, but when I first viewed it, it didn't wrap, thats what made me check the wrap X in the scene.

I also tested unchecking Movable, as I've seen others say if its unchecked it stops other actors from moving the background, but when I did this, the background wouldn't scroll

So I guess the main question now is, Is this the best way for me to do what Im trying to achieve, or is there a better way?

If the way I've done it is fine, then I'll post the template for others to use and hope it works for them as well.

Download UfoBlaster on the iTunes store

Best Answer

  • stueynetstueynet TorontoPosts: 166
    Accepted Answer

    @aussiefaz said:
    Stueynet, when you say a double wide actor, does this mean that because the scene is 1024, the actor itself should be 2048?

    Here I made a quick template for you

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

Answers

  • aussiefazaussiefaz Member, PRO Posts: 86

    hmm, I just noticed that as the back edge of each actor reaches 0 point the screen flashes black right on the edge, just for a spilt second.

    I've attached the zip file in case one of you would like to look it over for me to see why that black flash happens.

    Download UfoBlaster on the iTunes store

  • stueynetstueynet TorontoMember Posts: 166
    edited April 2014

    I make the background actor double the size of the screen (in your case the same size as the scene itself).

    Under graphics

    • Horizontal Wrap: Tile

    • Vertical Wrap: Stretch

    • Tile Width: Screen Width (1024 for you)

    • Tile Height: Screen Height (768 for you)

    The a simple rule:

    WHEN

    *self.postion.x <= 1

    *change attribute: self.position.x to display width (1024 for you)

    So basically you need a double wide actor because when it starts moving, you don't want to see the empty background.

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

  • stueynetstueynet TorontoMember Posts: 166

    @stueynet said:
    I make the background actor double the size of the screen (in your case the same size as the scene itself).

    Under graphics

    • Horizontal Wrap: Tile
    • Vertical Wrap: Stretch
    • Tile Width: Screen Width (1024 for you)
    • Tile Height: Screen Height (768 for you)

    The a simple rule:

    WHEN
    self.postion.x <= 1
    change attribute: self.position.x to display width (1024 for you)

    So basically you need a double wide actor because when it starts moving, you don't want to see the empty background.

    The editor in this forum really formats posts nicely.

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

  • aussiefazaussiefaz Member, PRO Posts: 86

    Stueynet, when you say a double wide actor, does this mean that because the scene is 1024, the actor itself should be 2048?

    Download UfoBlaster on the iTunes store

  • stueynetstueynet TorontoMember Posts: 166

    @aussiefaz said:
    Stueynet, when you say a double wide actor, does this mean that because the scene is 1024, the actor itself should be 2048?

    Yes. But the graphic on it would be 1024 wide. And then you simply tile it horizontally. The other option is you can use 2 actors side by side but that usually ends up with a seem.

    Also please @stueynet‌ my name or I won't know you replied to me.

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

  • aussiefazaussiefaz Member, PRO Posts: 86

    @stueynet said:
    Here I made a quick template for you

    Awesome thanks. I just checked the template. I had everything else working on mine, but I still had the scene overall size at 2048 from my first post at top and every now and then the tile wouldn't show up and I'd get black.

    I changed the scene back to 1024 and this works seamlessly now

    Download UfoBlaster on the iTunes store

  • aussiefazaussiefaz Member, PRO Posts: 86

    @stueynet‌ I did notice one thing, every now and then it gets a tiny little shake to the background. Any reason why it would do that?

    Download UfoBlaster on the iTunes store

  • stueynetstueynet TorontoMember Posts: 166

    @aussiefaz said:
    stueynet‌ I did notice one thing, every now and then it gets a tiny little shake to the background. Any reason why it would do that?

    Are you seeing that in your file or the template. I know that there are performance issues that show up in scrolling backgrounds if your game has a lot of constrains.

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

  • aussiefazaussiefaz Member, PRO Posts: 86

    @stueynet said:

    Im just seeing it in the template when viewing it. All the template has in it, was the background at this stage, so nothing else was running.

    I'll work with it as is for now and see when I publish it, if its still doing it

    Download UfoBlaster on the iTunes store

Sign In or Register to comment.