Hi, I have written the code below to create an animation and a line that shifts from the right to the left. My problem is that if the line is no longer under the sprite, the sprite doesn’t fall down.
local sheet1 = graphics.newImageSheet( "hero.png", { width=135, height=259, numFrames=14 } ) local hero = display.newSprite( sheet1, { name="hero", start=1, count=14, time=450 } ) hero.timeScale = 1.0 hero.x = \_W/2-400 hero.y = \_H/2+180 hero.alpha = 1 hero.myName = "hero" hero:play() physics.addBody( hero, "dynamic", { friction=0.0, bounce=0 } ) hero.isFixedRotation=true local linea = display.newRect(\_H/2,math.random(\_H/2+290,\_H/2+400),1250,10) linea:setFillColor(255,0,0) linea.alpha = 0.5 linea.myName = "linea" physics.addBody(linea, "static", { friction = 0, bounce = 0 } ) local function muoviLinea() linea.x = linea.x - velocita linea2.x = linea2.x - velocita if(linea.x\<-712)then linea.x = \_W/2 linea.y = math.random(\_H/2+290,\_H/2+400) end end Runtime:addEventListener("enterFrame", muoviLinea)
If, instead of a sprite, I use
local hero = display.newRect(100,100,10,10) physics.addBody( hero, "dynamic", { friction=0.0, bounce=0 } )
Everything works as it should.
What am I doing wrong? Thank you.