Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Lua
hi
i have created game where a user will have to match buttons on the screen. The screen contains 12 buttons on a grid which all work well. My Problem is that i want to change the scene to a scene named "congrats" when the user matches all the buttons . I am currently having difficult with as i don't how or where to change scene when their is no buttons left on the screen can someone me plz?
 
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
physics = require("physics")
physics.start()
physics.setGravity(0, 9.8)
--Set Global width and height variables
_W = display.contentWidth;
_H = display.contentHeight;
--Hide status bar
display.setStatusBar(display.HiddenStatusBar);
--Declare a totalButtons variable to track number of buttons on screen
local totalButtons = 0
--Declare variable to track button select
local secondSelect = 0
local checkForMatch = false
--Set up game function
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
matchText.text = "Match Found!";
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
physics.addBody(lastButton, {density = 2.0, friction = 1.5, bounce=0.0})
physics.addBody(object, {density = 2.0, friction = 1.5, bounce=0.0})
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
end, 1)
end
end
end
end
end
function scene:createScene( event )
local screenGroup = self.view
--Declare button, buttonCover, and buttonImages table
button = {}
--screenGroup:insert( button )
buttonCover = {}
--screenGroup:insert( buttonCover )
buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5,6,6}
--screenGroup:insert( buttonImages )
--Declare and prime a last button selected variable
lastButton = display.newImage("1.png");
lastButton.myName = 1;
screenGroup:insert( lastButton )
--Set up simple off-white background
myRectangle = display.newRect(0, 0, _W, _H)
myRectangle:setFillColor(235, 235, 235)
screenGroup:insert( myRectangle )
--Notify player if match is found or not
matchText = display.newText(" ", 0, 0, native.systemFont, 26)
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor(0, 0, 0)
matchText.x = _W/2
screenGroup:insert( matchText )
--Place buttons on screen
for count = 1,3 do
x = x + 90
y = 20
for insideCount = 1,4 do
y = y + 90
--Assign each image a random location on grid
temp = math.random(1,#buttonImages)
button[count] = display.newImage(buttonImages[temp] .. ".png");
--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("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
print( "\n1: createScene event")
end
function scene:enterScene( event )
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener(</code> "destroyScene", scene )
return scene

when all the buttons have been removed from the screen, I would my app to change scene.

Thank You
Posted 11-May-13 16:34pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are more likely to get good help at http://www.coronalabs.com/products/corona-sdk/[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100