Removing Image

I’m trying to make a visual Level display image appear on my screen and then change the image’s picture to match the picture that goes with the players current level. I have it working so it draws the level label like it should each time the player gains a level, the problem is that it’s not removing the old image and is just drawing the new one ontop of it. The following is the current code I’m using that has to do with drawing/removing the image.

local curLevel = 0  
local curLevelTime = 0;  
local SpawnTimer = 1000;  
  
function controlData( ) -- Create new rocks  
 if ( gameState == "Play" ) then  
 display.remove( dropRocks )   
 display.remove( LevelDisp )   
 -- Spawn Rocks  
 local dropRocks = timer.performWithDelay( SpawnTimer, newRock, 99999 )  
 -- Level Display  
 local LevelDisp = display.newImage( "Lvl".. curLevel ..".png" )  
 LevelDisp.x = 50  
 LevelDisp.y = 105  
 end  
end  
  
-- Check if levelTime has passed and if so, call levelup player  
local function levelTime( event )  
 if (curLevel \< 6 ) then  
 if ( NextTimer == curLevelTime ) then  
 curLevel = curLevel + 1  
 curLevelTime = curLevelTime + 20  
 SpawnTimer = SpawnTimer -100;  
 display.remove( dropRocks )   
 controlData()  
 end  
 else  
 gameState = "Pause"  
 end  
end  
  
 local checkTime = timer.performWithDelay( 500, levelTime, 1000 )  

I was wondering if anyone can point out what I’m missing here to get this working correctly. [import]uid: 69700 topic_id: 11502 reply_id: 311502[/import]

I’m still having problems with removing Images, although the above example has now been changed and is working, I still need help with the general question. Now I have a code that creates blocks (platforms) in random cords that can be moved by touching and dragging them around the screen. The problem I’m having is that when you move on to the next level I need it to delete the all of the blocks that are currently active. I can’t get this to work and its just making them invisible but they are still there.

The following is my code for creating blocks/moving blocks. I need it so that when gameState doesn’t equal play it deletes all blocks. The way I have it now you have to touch the block once the gameState has changed from play to delete this, but this solution wont work because people would just not click them and keep them active for the next level.

[code]
local makeWallTime = 0
local createWallTime = 10

local function onBlockCollision( self, event ) – Delete block
if ( event.phase == “began” ) then
display.remove( self )
self = nil
elseif ( event.phase == “ended” ) then
end
end

local n = 1

local blockColors = {
{0, 0, 0}, {128, 0, 0}, {255, 0, 0}, {255, 0, 255},
{0,128, 128}, {0, 128, 0}, {0, 255, 0}, {0, 255, 255},
{0, 0, 128}, {128, 0, 128}, {0, 0, 255}, {192, 192, 192},
{128, 128, 128}, {192, 128, 0}, {255, 255, 0}, {255, 255, 255}
}

local function createWall( event )
if ( gameState == “Play” ) then
—X - Y - Width - Height----
local block = display.newRect( math.random (40 , 75), math.random (130 , 250), 30, 4.5 )
n = n + math.random (1 , 5)
local rgb = blockColors[n]
block:setFillColor( rgb[1], rgb[2], rgb[3])
physics.addBody( block, “static” )
block.collision = onBlockCollision
block:addEventListener( “collision”, block )
groupOne:insert( block )

local function onTouch( event )
local blockmoved = event.target
local phase = event.phase
if ( gameState == “Play” ) then
if “began” == phase then
– Make target the top-most object
local parent = blockmoved.parent
parent:insert( blockmoved )
display.getCurrentStage():setFocus( blockmoved )
blockmoved.isFocus = true
– Store initial position
blockmoved.x0 = event.x - blockmoved.x
blockmoved.y0 = event.y - blockmoved.y
elseif blockmoved.isFocus then
if “moved” == phase then
blockmoved.x = event.x - blockmoved.x0
blockmoved.y = event.y - blockmoved.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
blockmoved.isFocus = false
end
end
return true
else
blockmoved.x = 0
blockmoved.y = 0
blockmoved.isFocus = false
display.remove( block )
blockmoved = nil
end
end
block:addEventListener( “touch”, onTouch ) – Let block be moved by touch
else
block.x = 0
block.y = 0
block.isFocus = false
display.remove( block )
block = nil
block:addEventListener( “touch”, onTouch ) – Let block be moved by touch
end
end

local WallTimer = display.newText( “…”, -100, -100, native.systemFont, 1 )

function WallTimer:timer( event )
if ( gameState == “Play” ) then
makeWallTime = event.count

if ( makeWallTime == createWallTime ) then
local makeWall = timer.performWithDelay( 100, createWall, 1 )
createWallTime = createWallTime + 10
end
else
event.count = 0
makeWallTime = 0
end
end

local WallTime = timer.performWithDelay( 500, WallTimer, 1000 )
[/code] [import]uid: 69700 topic_id: 11502 reply_id: 42077[/import]