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:1716 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
相关文章
Build failed: doesnt accept login/password
Text Alignment in String
How to set different gravity for each level ?
One Button, Multiple touch events
Trial Users, Don't Upgrade to 2011.703
log in account system?
PONG BEATS made into "New & Noteworthy" - Thanks Corona
function order
GlowTunes reinvents the Christmas tree for iPhone and iPad!
Augmented Reality?
Text Alignment in String
How to set different gravity for each level ?
One Button, Multiple touch events
Trial Users, Don't Upgrade to 2011.703
log in account system?
PONG BEATS made into "New & Noteworthy" - Thanks Corona
function order
GlowTunes reinvents the Christmas tree for iPhone and iPad!
Augmented Reality?
corona forums © 2003-2011