I would like my game to reset when the player taps on the Play Again button that shows on my last screen. When that button is tapped. I want the results from the last game to clear and the screen changes with director which I am using and the player can start fresh. Here is my code below for that screen. Could somebody tell me what code I can add to reset the level? I have a global variable that is being pulled from the previous screen which is then supplying this screen with an answer. I would need the result on this screen which is in numberFieldReminder to clear out when the game resets and take the person to the titlescreen.
I have everything working properly on this screen except for the reset part that would clear the screen.
Can somebody assist?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | module(..., package.seeall) function new() local localGroup = display.newGroup() local inputFontSize = 80 local inputFontHeight = 80 local tHeight = 100 local ui = require("ui") local number if _G.numberSix ~= nil then number = _G.numberSix elseif _G.numberTen ~= nil then number = _G.numberTen else number = 0 end local screen9 = display.newImage ("screen9.png") localGroup:insert(screen9) --> This sets Screen9 local playbutton = display.newImage ("play.png") localGroup:insert(playbutton) playbutton.x = 100 playbutton.y = 55 playbutton.xScale = .5 playbutton.yScale = .5 local function playbuttonfn (event) director:changeScene( "titlescreen", "flip" ) media.playEventSound( "bloop_x.caf" ) end playbutton:addEventListener ("tap", playbuttonfn) local cleanUp = function() play:removeEventListener ("touch", touchedPlay) end --setting to avoid the error if divisionBal == nil then divisionBal = 0 end if digitSum == nil then digitSum =0 end -- the sum value will be in digitSum -- reminder value will be in divisionBal -- show the reminder in a textfield numberFieldReminder = native.newTextField( 180, 315, 85, tHeight, onnumberFieldReminder) numberFieldReminder.font = native.newFont( native.systemFontBold, inputFontSize ) numberFieldReminder.inputType = "number" numberFieldReminder.align = "center" numberFieldReminder.text = divisionBal localGroup:insert(numberFieldReminder) -->MUST return a display.newGroup() ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ --> This is how we end every file except for director and main, as mentioned in my first comment return localGroup end |
I'm told that if I turn my new.textField into a display.newText that I should be able to do what I need. How do I turn the code to that? What are the parameters for that?
just set all the global variables that you have created to nil. this will reset the game.
and if you want to create a display text just use
local mytext = display.newText("",x,y,nil,25)
you can specify your text inside the quotes. x and y are position of text, nil means we are not using any custom fonts and 25 is the size of the text.
you can set the text property of that text object to show your text.
mytext.text = "Hello World"
Thank you changing the global variables fixed this!!!