Having problems with sidescrolling leapfrog effect

Hey,

I have started working on a new project and I am having probs with the sidescrolling leap effect (background leaps to the other side when hits a certain point). I tried translating this Lua code:

function scrollCity(self,event)
if self.x < -568 then
self.x = 568
else
self.x = self.x - self.speed
end
end

self is the background

For self.speed, I created an actor attribute (integer) but later changed my mind and used the move behaviour instead.
Here are some screenshots of my GameSalad code:

http://imgur.com/wZpnPqN,abI9AUB

What I want it to do is scroll infinitely and when it goes to -568 on X, to leap all the way back to 568 X.

-The background moves
-The background goes all the way off the screen
-It doesn't change is position

What am I doing wrong?

Comments

  • BBEnkBBEnk Member Posts: 1,764
    I assume your image is 568 width so You only need to go -284 and leap back to 852.. zero is the center of the image.
  • kinzuakinzua Member Posts: 554
    why is the background moving off the scene?

    i believe if you make it move forward and then back to the edge of the scene, you'll get your result. Just make the screen size that big. I mean at least make it 568*2.

    or rather what i figure out, is that your player is on the edge of the screen. Keep it upfront and move the camera too, accordingly and u should be through with this. I don't see much of an issue in here.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Actors destroy automatically when they go past -500px so before this "if (self.x < -568)" is happening it's already destroyed. You also have to keep in mind that the x and y of an actor by default is in the centre so you probably want something like this:

    function scrollCity(self,event)
    if self.x < -284 then
    self.x = 284
    else
    self.x = self.x - self.speed
    end
    end

    I've used 284 because it would be the centre of the image/actor.

    I have an example where I'm scrolling 3 backgrounds which I can send later if you're still having trouble.
  • alexconsincalexconsinc Member Posts: 54
    @BBEnk and @KevinCross Thanks, this worked
Sign In or Register to comment.