EDIT: Moved the the area for displaying wall1 above wall and it fixed the problem… That’s odd…
I’m working on a little game and when a transition is done a wall should go remove itself and go restart. I have this set up as a loop so it goes on until it gets hit. I’ll explain better after posting the relevant code, the comments are explaining the issue and what the code does:
[lua]
–The movement for wall
transSpeed = 2500
function moveObs( )
moveObsTrans = transition.to( wall, { time=transSpeed, x=0, onComplete=restartObs } )
print( transSpeed )
end
----The movement for wall1
function moveObs2( )
moveObsTrans2 = transition.to( wall1, { time=transSpeed, x=0, onComplete=restartObs2 } )
print( “moving wall1” )
end
–It’s printing “removed wall1,” but not actually removing it from the display. And it keeps doing this when it should but the wall stays at x=0 without being removed or restarting.
function restartObs2( )
display.remove( wall1 )
print( “removed wall1” )
end
function restartObs( )
display.remove( wall )
print( “removed wall” )
if transSpeed > 2000 then
transSpeed = transSpeed - 25
elseif transSpeed > 1500 and transSpeed <= 2000 then
transSpeed = transSpeed - 50
elseif transSpeed > 1000 and transSpeed <= 1500 then
transSpeed = transSpeed - 100
end
i = 2–math.random( 1, 4 )
if i == 1 then
--This one works exactly as it should.
wall1 = display.newImageRect( “Wall1.png”, 35, 100 )
wall1.x = display.contentWidth/1 + 30
wall1.y = display.contentHeight
wall1:scale( -1, -1 )
wall1.isReal = false
physics.addBody( wall1, { density = 1.0, friction = 0, bounce = 0 } )
moveObs2()
wall = display.newImageRect( “Wall1.png”, 35, 250 )
wall.x = display.contentWidth/1 + 30
wall.y = display.contentHeight/1.33
wall:scale( -1, 1 )
physics.addBody( wall, { density = 1.0, friction = 0, bounce = 0 } )
moveObs()
print( “moving wall” )
elseif i == 2 then
--Despite being practically identical to the first one, this one doesn’t work as it should. What gives?
wall = display.newImageRect( “Wall1.png”, 35, 350 )
wall.x = display.contentWidth/1 + 30
wall.y = display.contentHeight/1
wall:scale( -1, 1 )
physics.addBody( wall, { density = 1.0, friction = 0, bounce = 0 } )
moveObs()
wall1 = display.newImageRect( “Wall1.png”, 35, 100 )
wall1.x = display.contentWidth/1 + 30
wall1.y = display.contentHeight/13
wall1:scale( -1, -1 )
wall1.isReal = false
physics.addBody( wall1, { density = 1.0, friction = 0, bounce = 0 } )
moveObs2()
print( “created wall1” )
end
[/lua]
The first one (i == 1) works exactly as it should, the second one, (i == 2) however, doesn’t work as it should, what gives?
I hate having to consult the forum on this one, but I’m just absolutely stumped and frustrated by this issue.