I'm trying to add a feature to my app where the user can double tap the screen to get to the menu. I'm using the director class, but it's not working out for me. Did I do anything wrong?
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 | local director = require("director"); local mainGroup = display.newGroup(); -- I put the above code first in my app, then the body, then the following... local function main () mainGroup:insert(director.directorView); director:changeScene("Menu"); return true; end local onTap = function(event) if 2 == event.numTaps then main(); return true; end end Runtime:addEventListener("tap", onTap) |
I think you will have to create a tap adding up function. eg:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | local taps = 0 local function countTaps(event) if event.phase == "began" then taps = taps + 1 end if taps == 2 then main() end end Runtime:addEventListener("tap", countTaps) local function main () mainGroup:insert(director.directorView); director:changeScene("Menu"); return true; end |
Ugh, that doesn't work either, my app just freezes and says something about assertion. My app is an alarm clock so far...
Argh!
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 | Runtime error assertion failed! stack traceback: [C]: ? [C]: in function 'assert' ?: in function 'getOrCreateTable' ?: in function 'addEventListener' ?: in function 'addEventListener' ...blah\blah\blah\Alarm Clock\Aclock.lua:93: in mRuntime error: assertion failed! stack traceback: [C]: ? [C]: in function 'assert' ?: in function 'getOrCreateTable' ?: in function 'addEventListener' ?: in function 'addEventListener' ...blah\blah\blah\Alarm Clock\Aclock.lua:93: in main chun k [C]:Runtime error ...blah\blah\blah\Alarm Clock\director.lua:303: ERROR: tabl e expected. If this is a function call, you might have used '.' instead of ':' stack traceback: [C]: ? [C]: in function 'insert' ...Blah\Blah\Blah\Alarm <lua> -- line 93 Runtime:addEventListener("tap", countTaps) -- line 303 in Director.lua file currView:insert(currScreen) |
Your main.lua should be something like below... Note line no 31 below.
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 | display.setStatusBar( display.HiddenStatusBar ) --------------------------------------------------------------- -- Import director class --------------------------------------------------------------- director = require("director") --------------------------------------------------------------- -- Create a main group --------------------------------------------------------------- local mainGroup = display.newGroup() --------------------------------------------------------------- -- Main function --------------------------------------------------------------- local function main() ----------------------------------- -- Add the group from director class ----------------------------------- mainGroup:insert(director.directorView) ----------------------------------- -- Change scene without effects ----------------------------------- director:changeScene("Aclock.lua") ----------------------------------- -- Return ----------------------------------- return true end --------------------------------------------------------------- -- Begin --------------------------------------------------------------- main() -- It's that easy! :-) |
That doesn't seem to work out well or maybe I did something wrong.
This is my tap function below, I think it should work but I just need an event listener. Do i need anything else in my file from the director class?
1 2 3 4 5 6 7 8 9 | local function changeScene(event) if (2 == event.numTaps) then director:changeScene("menu") end end |
views:1717 update:2011/10/2 9:44:12
热门文章
GameCenter LeaderBoards and Achievements Enabled Through OpenFeint
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
相关文章
Default.png
how can I make moving objects to event go slower the further they are away?
Install failed on Kindle Fire
Problem with json.decode
Physics joint issue
Movieclips do not drag when rotated for orientation
Moving player + scrolling background + obstacle = problem
No puedo ver algunas páginas siendo usuario subscrito
Step by step corona UI tutorial ?
Objected Oriented Lua (OO..Lala)
how can I make moving objects to event go slower the further they are away?
Install failed on Kindle Fire
Problem with json.decode
Physics joint issue
Movieclips do not drag when rotated for orientation
Moving player + scrolling background + obstacle = problem
No puedo ver algunas páginas siendo usuario subscrito
Step by step corona UI tutorial ?
Objected Oriented Lua (OO..Lala)
corona forums © 2003-2011