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]