How create a game which scrolls down the screen. (Like the game Falldown)

Hi, I am new to Corona and was wandering how to do something which is similar to Falldown (but will have a different purpose). So far I have:

local function createNewFloors() randomno = math.random (display.contentWidth/4, display.contentWidth\*3/4) -- random width of left floor, from 1/4 to 3/4 of the screen width floorR = display.newImage("floorRR.png", 0 , -60) floorL = display.newImage("floorLL.png", 0 , -60) floorR.anchorX = 0 --reference X at left of floorR floorL.anchorX = 1 --reference X at right of floorL floorL.x = randomno floorR.x = randomno+30 physics.addBody(floorL, {density = 99999}) -- not static or they won't move physics.addBody(floorR, {density = 99999}) -- high density or the ball will affect its movement floorL:setLinearVelocity(0,-50)-- so the floors go up floorR:setLinearVelocity(0,-50) timer.performWithDelay (1500, createNewFloors) end Runtime:addEventListener("enterFrame", createNewFloors)

So basicly, it will create FloorLL and the left side and FloorRR on the right side but in random places, but it has a 30pixel or more gap imbetween. However, all this does is create about 1 floor every 0.5 of a second and spamms it without it being static so it falls. Can anyone help? Thanks

I’d consider doing it the other way round. Make the platforms static and move them using transition.to or on an enterFrame event, and move the background if you like. So you aren’t on a screen where the player is falling down, it’s a static screen where everything is going up - then when your platforms go off the top, recycle them.

Ahhh, that is a good idea. But what if I need the holes in the rows to be in different places?

Move the platforms horizontally ? It depends really. 

If you want at most 2 holes in each (guessing here) then you could have three platforms which you rescale every time you recycle them round (rescale and reposition horizontally). Or you could make each platform line out of eight subsections and create a hole by moving the ones you don’t want off screen somewhere

This kind of thing you keep an array of the platform part objects, and when you recycle them you move them down to the bottom of the screen, anything you don’t want gets put way off to the left, out of the game space. Note I haven’t tried this :slight_smile:

function platformRecycle(platformArray,hole1,hole2) -- move any platforms moved out of the way back, and put platforms at the screen bottom. for \_,platform in ipairs(platformArray) do if platform.x \< -100 then platform.x = platform.x + 1000 end platform.y = display.contentHeight end -- move all unwanted platforms off to the far left. if hole1 ~= nil then platformArray[hole1].x = platformArray[hole1].x - 1000 end if hole2 ~= nil then platformArray[hole2].x = platformArray[hole2].x - 1000 end end 

Then put an enter frame event in and move each platform up a bit, when it reaches the top, recycle it with new holes.

Then just have an array of platform arrays.

I mean verticle, like this with the random holes in: http://gyazo.com/093faadc6194caefa966934e521d750f.

Also, how would I make a parallax background that goes vertical, have you got any links to tutorials if it is to complicated to explain? Thanks

Yep, it was vertical , I don’t know why I wrote horizontal.

Parallax, I would google for it. There will be plenty of examples, just look for one which explains the theory, it doesn’t have to be Corona specific. The basic idea is you have multiple backgrounds that travel at different speeds giving an illusion of depth, so horizontally you might have mountains in the background scrolling faster than clouds in the foregrounds. Not quite sure how you would do it vertically though. 

If you are doing a vertical scrolling game and you think the background could be a bit dull, you could have tiles for it which change occasionally as you go into different areas of the game, signs with different writing on etc.

Yeah, I have looked on Google and Youtube and there is this VERY good example, however this seems to be giving me a problem. (at 4:20)      

 https://www.youtube.com/watch?v=G5RarQ03MZA 

I have looked for alternate solutions for self.x = self.x - 3

Also, you I just change it all to self.y and the others to Y and my screen size for it to go vertical?

[EDIT] self.y = self.y works but it is when I add something on the end such as the ‘- 3’

It would probably work, it depends how this chap achieves the wrap around effect. Sometimes they have two images, as you scroll one off you scroll the other one on. So it might be slightly different.

Can’t see a reason why self.y = self.y works and self.y = self.y - 3 doesn’t other than self.y being something other than a number - nil,  a string or something. Doing -3 implicitly cases self.y to a number if it can 

Well, what I have is this

local stars1 = display.newImage("stars.png", 160, 250) local stars2 = display.newImage("stars.png", 160, 750) local planetsbackground1 = display.newImage("planets.png", 160, 250) local planetsbackground2 = display.newImage("planets.png", 160, 750) function scrollstars(self,event) self.y = self.y - 3 end stars1.enterFrame = scrollstars Runtime:addEventListener("enterFrame", scrollstars)

Will it not work because I am not using ‘setReferencePoint’? Because I cannot use that and I have to use ‘anchor’ instead. 

I’d consider doing it the other way round. Make the platforms static and move them using transition.to or on an enterFrame event, and move the background if you like. So you aren’t on a screen where the player is falling down, it’s a static screen where everything is going up - then when your platforms go off the top, recycle them.

Ahhh, that is a good idea. But what if I need the holes in the rows to be in different places?

Move the platforms horizontally ? It depends really. 

If you want at most 2 holes in each (guessing here) then you could have three platforms which you rescale every time you recycle them round (rescale and reposition horizontally). Or you could make each platform line out of eight subsections and create a hole by moving the ones you don’t want off screen somewhere

This kind of thing you keep an array of the platform part objects, and when you recycle them you move them down to the bottom of the screen, anything you don’t want gets put way off to the left, out of the game space. Note I haven’t tried this :slight_smile:

function platformRecycle(platformArray,hole1,hole2) -- move any platforms moved out of the way back, and put platforms at the screen bottom. for \_,platform in ipairs(platformArray) do if platform.x \< -100 then platform.x = platform.x + 1000 end platform.y = display.contentHeight end -- move all unwanted platforms off to the far left. if hole1 ~= nil then platformArray[hole1].x = platformArray[hole1].x - 1000 end if hole2 ~= nil then platformArray[hole2].x = platformArray[hole2].x - 1000 end end 

Then put an enter frame event in and move each platform up a bit, when it reaches the top, recycle it with new holes.

Then just have an array of platform arrays.

I mean verticle, like this with the random holes in: http://gyazo.com/093faadc6194caefa966934e521d750f.

Also, how would I make a parallax background that goes vertical, have you got any links to tutorials if it is to complicated to explain? Thanks

Yep, it was vertical , I don’t know why I wrote horizontal.

Parallax, I would google for it. There will be plenty of examples, just look for one which explains the theory, it doesn’t have to be Corona specific. The basic idea is you have multiple backgrounds that travel at different speeds giving an illusion of depth, so horizontally you might have mountains in the background scrolling faster than clouds in the foregrounds. Not quite sure how you would do it vertically though. 

If you are doing a vertical scrolling game and you think the background could be a bit dull, you could have tiles for it which change occasionally as you go into different areas of the game, signs with different writing on etc.

Yeah, I have looked on Google and Youtube and there is this VERY good example, however this seems to be giving me a problem. (at 4:20)      

 https://www.youtube.com/watch?v=G5RarQ03MZA 

I have looked for alternate solutions for self.x = self.x - 3

Also, you I just change it all to self.y and the others to Y and my screen size for it to go vertical?

[EDIT] self.y = self.y works but it is when I add something on the end such as the ‘- 3’

It would probably work, it depends how this chap achieves the wrap around effect. Sometimes they have two images, as you scroll one off you scroll the other one on. So it might be slightly different.

Can’t see a reason why self.y = self.y works and self.y = self.y - 3 doesn’t other than self.y being something other than a number - nil,  a string or something. Doing -3 implicitly cases self.y to a number if it can 

Well, what I have is this

local stars1 = display.newImage("stars.png", 160, 250) local stars2 = display.newImage("stars.png", 160, 750) local planetsbackground1 = display.newImage("planets.png", 160, 250) local planetsbackground2 = display.newImage("planets.png", 160, 750) function scrollstars(self,event) self.y = self.y - 3 end stars1.enterFrame = scrollstars Runtime:addEventListener("enterFrame", scrollstars)

Will it not work because I am not using ‘setReferencePoint’? Because I cannot use that and I have to use ‘anchor’ instead.