When my game completes it brings up a try again or congratulations you completed the level. How do i reset the level after a try again?
I want to move all pieces back to their original location on the board.
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
When my game completes it brings up a try again or congratulations you completed the level. How do i reset the level after a try again?
I want to move all pieces back to their original location on the board.
Depends on how your game is set up.. gonna have to post some code.
I'm not sure what code you are looking for. The code below is what I show at the completion of the game. It brings up a positive or a negative response. When I click the alert it disappears but the board is in the same position it completed in.
1 2 3 4 5 6 7 8 9 10 | if (findBlock(1,1) == findBlock(1,2)) then native.showAlert("Uh-oh","You can't do that.",{"Try Again"}); --this stops our alert box from showing return false end --DO STUFF native.showAlert("level complete","success",{"Awesome!"}); return true end |
I recommend using director class, and just reloading the lvl.lua
How do I do that? I am using the director.lua file
Do I just place a reset button, tie to the page and reload the screen like I am transitioning to the page again?
You just need two files.. you need your level file.. and then you need a load level file. When your game is over.. and you click retry.. the retry button would switch scenes to your load level file..
1 | director:changeScene( loadLevel, "crossfade" ) |
Okay I have the level file and the load level file is just similar to the file I have to transition from my splash screen to my titlescreen so I get that.
In regards to the director line. Where do I put that line? Do I put that with the coding above that I posted after the alert as an if then statement?
Ive never worked with native.showAlert before.. but this link shows what you would need to do..
http://developer.anscamobile.com/reference/index/nativeshowalert
It looks to me though, that whatever index your "retry" button is, is where you would put the director line.
For instance if your retry button is indexed as 1.. then..
1 2 3 4 5 6 7 8 | local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then director:changeScene( loadLevel) end end end |
who can i reset my modeule? or even remove the LEVEL 1 = REQUIRE?
thanks
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 | module(..., package.seeall) function new() local localGroup = display.newGroup() local level1 = require ("nivel1") --localGroup:insert(level1) local backbutton = display.newImage ("images/interfas/backbutton.png") backbutton.x = 160 backbutton.y = 350 localGroup:insert(backbutton) --> This places our "back" button local function pressBack (event) if event.phase == "ended" then director:changeScene ("menu") Runtime:removeEventListener("enterFrame",gameListener) end end backbutton:addEventListener ("touch", pressBack) --> This adds the function and listener to the "back" button ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ return localGroup end |