Obstacles generation

Hi everyone!
I’m new to programming with corona and i’m trying to make this code work and it does but i have some problems with putting it into composer, hope someone can give me an advice! :slight_smile:

local barriere = {}

local function creaBarriere(event)
local barriera
barriera = display.newImageRect(fg,“transenna2.png”,1000,1000)
–corpo fisico degli ostacol
barriera.x = 1380+math.random(50,300)
barriera.y = display.contentHeight+400

physics.addBody(barriera,“static”,{density=3.0, shape=formaBarriere,bounce=0.0})
barriera.name=“barriera”

barriera:toFront()
table.insert(barriere,barriera)
return barriera

end
local formaBarriere = {50,-200,200,300,-200,300}

local function barrierScroll(self,event)
    local speed_3 = 30
    self.x =self.x - speed_3
end

local function gameLoop()
local barriera = creaBarriere()
barriera.enterFrame = barrierScroll
Runtime:addEventListener(“enterFrame”, barriera)
print(#barriere)
for i,thisBarrier in ipairs(barriere) do
if thisBarrier.x < -80 then
Runtime:removeEventListener(“enterFrame”,thisBarrier)
display.remove(thisBarrier)
table.remove(barriere,i)
end
end
end

local gameLoopTimer = timer.performWithDelay(2000,gameLoop,0)

You don’t need composer. None of my games use it.

Yeah I know it was working without composer but i want to learn how to use it :slight_smile:

Best is to follow the tutorials.

Hello.

  1. Format your code properly. Every line in it should be between opening (´´´) and closing (´´´) marks.

  2. Use a more descriptive title. Could be something like “Help setting up composer in my project”

  3. Composer is a library provided by Solar2D that helps you to manage scenes and transitions between them. As SGS states, you are not obliget to use it. Have you done the “Getting Started” Guide? It introduces composer in Chapter 4 (https://docs.coronalabs.com/guide/programming/04/index.html), though i recommend you complete it from Chapter 1, as it will help you master composer being used in context.