i want to remove
buttonCover
button
buttonCoverImage
after use function storyboard.gotoScene
but i use
– :removeSelf() it’s error
how i can do it?
[lua]local storyboard = require “storyboard”
local scene = storyboard.newScene()
local totalButtons = 0
local set = math.random(4)
local secondSelect = 0
local checkForMatch = false
local button = {}
local buttonCover = {}
local buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5, 6,6}
local lastButton = display.newImage(“picGame/match/1/1.png”);
lastButton.myName = 1;
local matchText = display.newText(" ", 0, 0, native.systemFont, 26)
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor(0, 0, 0)
matchText.x = _W/2
local count = 6
x = -20
local myBg
function scene:createScene( event )
local group = self.view
myBg = display.newImageRect( “picGame/match/bg.png” ,768 , 1023)
myBg.x = display.contentWidth * 0.5 ; myBg.y = display.contentHeight * 0.5
function game(object, event)
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
–Flip over first button
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect == 0) then
–Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
–If buttons do not match, flip buttons over
if(lastButton.myName ~= object.myName) then
matchText.text = “Match Not Found!”;
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
end, 1)
–If buttons DO match, remove buttons
elseif(lastButton.myName == object.myName) then
count = count - 1
matchText.text = “Match Found!”;
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
end, 1)
end
end
end
end
if(count == 0) then
print(“EMP win”)
end
end
–Place buttons on screen
for count = 1,3 do
x = x + 200
y = 25
for insideCount = 1,4 do
y = y + 200
–Assign each image a random location on grid
temp = math.random(1,#buttonImages)
if (set == 1) then
button[count] = display.newImage(“picGame/match/1/” … buttonImages[temp] … “.png”);
end
–Position the button
button[count].x = x;
button[count].y = y;
–Give each a button a name
button[count].myName = buttonImages[temp]
button[count].number = totalButtons
–Remove button from buttonImages table
table.remove(buttonImages, temp)
–Set a cover to hide the button image
buttonCover[totalButtons] = display.newImage(“picGame/match/button.png”);
buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y;
totalButtons = totalButtons + 1
–Attach listener event to each button
button[count].touch = game
button[count]:addEventListener( “touch”, button[count] )
end
end
group:insert( myBg )
end
function scene:enterScene( event )
local group = self.view
lastButton:removeSelf()
lastButton = nil
storyboard.removeAll()
end
function scene:exitScene( event )
local group = self.view
end
function scene:destroyScene( event )
local group = self.view
end
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene[/lua] [import]uid: 169163 topic_id: 30087 reply_id: 330087[/import]