I am currently working on a game what requires an inventory system. I cannot work out how to make an exit button for a display object I created.
Here is my code :
local Choose_slot = display.newImage("Images/choose_slot.png")
Choose_slot.x = centerX + 96
Choose_slot.y = 45
function choose_slot:tap ( event )
Inventory_Screen = display.newRect( centerX, centerY, 1500, 1500 )
Inventory_Screen:setFillColor( 0.3, 0.3, 0.3 )
end
local Exit_Button = display.newImageRect( "Images/Exit_Image.png", 32, 32)
Exit_Button.x = centerX + 255
Exit_Button.y = centerY - 135
function Exit_Inventory:tap ( event )
Inventory_Screen:remove()
Exit_Button:remove()
end
Exit_Inventory:addEventListener( "tap", Exit_Button)
Choose_slot:addEventListener( "tap", choose_slot)
Just for your Information, "Choose_slot" is an image that brings up the inventory. I would like to make it so when the "Inventory_Screen" comes up the "Exit_Inventory" button pops up and when you tap it, it removes the "Inventory_Screen" and the "Exit_Button" from the screen and goes back to screen you were on before you clicked inventory!
The picture is what left after I changed your code to this:
function Choose_slot:tap ( event )
Inventory_Screen = display.newRect( centerX, centerY, 1500, 1500 )
Inventory_Screen:setFillColor( 0.3, 0.3, 0.3 )
local function handleExitBEvent( event ) -- ERROR IS BELOW!
if ( "ended" == event.phase ) then
print( "Button was pressed and released" )
print( "Removing Inventory!" )
Choose_slot:removeSelf() -- This is not removing --
ExitB:removeSelf()
Inventory_Screen:removeSelf()
Inventory_Slot1:removeSelf()
end
end