Question

Hey all i've been scowering the internet for days now, ive also been reading up on this etc and i am in desperate need of help. I am writing a 2D game and I need the background to move and my character will be stationary and he'll jump over stuff.

If anyone can push me in the right direction or even provide a snippet of code i would be more than greatful.

Was it helpful?

Solution 2

For anyone who is still struggling with this I worked it out:

Download corona SDK and program with that its so much easier:

function scrollBackground(self,event)
if self.x < [Enter Background width in pixels] then
self.x = [Enter Background width in pixels]
else
            self.x = self.x - [Speed - low number like 5 is slow scrolling, high number like 18 is fast scrolling]
        end
    end 

Use the above function to for the scrolling background then add this underneath:

function scene:enterScene(event)
background.enterFrame = scrollCity
Runtime:addEventListener("enterFrame", background)

OTHER TIPS

I think the easiest way to do this is to draw the background image twice as your character scrolls with something like this, but I'm not sure how to do it with HorizontalScrollView.

//x , y, width, height
Background b1 = new Background(0, screenHeight/2, screenWidth, screenHeight);
Background b2 = new Background(screenWidth, screenHeight/2, screenWidth, screenHeight);

//update loop
b1.x-=speed;
b2.x-=speed;

if(b1.x+b1.width/2<0){
   b1.x=b2.x+b2.width/2+b1.width/2;
}
if(b2.x+b2.width/2<0){
   b2.x=b1.x+b1.width/2+b2.width/2;
}

You could use this sort of method with multiple types of background images that you update at different speeds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top