double tap

Hello to all.

I am trying to create the ability to “double tap”. In other words imagine a frog. one tap is one leap into the air. The second tap sends the frog hire and farther (second tap). But the second tap is the limit. I’m not sure how to do that.

The code I have is thus:

local function moveFrog( event )

    if ( event.phase == “began” ) then

        --code executed when the frog is touched

        frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )

    end

    return true  --prevents touch propagation to underlying objects

end

frogBody:addEventListener( “touch”, moveFrog )  --add a “touch” listener to the frog body

use the tap event instead of touch

http://docs.coronalabs.com/api/event/tap/index.html

Hello Jstrahan.

Thanks for the input but I tried that already That doesn’t work…

should I use it all the time. post the code your using with it I’ll see if I can help

Thanks.

Here’s what I have so far (not much):

– Main.lua


– include Corona’s “physics” library

local physics = require “physics”

–physics.setGravity(0, 9.2);

physics.start(); --physics.pause();


– forward declarations and other locals

local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth*0.5, display.contentHeight*0.5


– BEGINNING OF YOUR IMPLEMENTATION

– 

– NOTE: Code outside of listener functions (below) will only be executed once,

–         unless storyboard.removeScene() is called.

– 


– Hide status bar


display.setStatusBar( display.HiddenStatusBar )


– Place the background


local background = display.newImage( “background.jpg”);

    background.anchorX = 0;

    background.anchorY = 0;

    

-----------------------------------------------------------------------------------------    

– Creat “frog”


local frogBody = display.newRect ( 60, 275, 55, 35 );

    frogBody:setFillColor( 0, 1, 0); 

    frogBody.strokeWidth = 3;

    frogBody:setStrokeColor( 0, 0, 0 );

    frogBody.rotation = -10;


– Creat “Lillypad”


local lillypad = display.newRect ( 60, 305, 80, 10 );

    lillypad:setFillColor( 0, .6, 0);

    lillypad.strokeWidth = 1;

    lillypad:setStrokeColor( 0, 0, 0 );


– add physics to the frogbody, Lilypad


physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );

physics.addBody( lillypad, “static”, { density=1.0, friction=0.3, bounce=.2 } )

local function moveFrog( event )

    if ( event.phase == “began” ) then

        --code executed when the frog is touched

        frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )

    end

    return true  --prevents touch propagation to underlying objects

end

frogBody:addEventListener( “touch”, moveFrog )  --add a “touch” listener to the frog body

-- -- Main.lua -- -----------------------------------------------------------------------------------------   -- include Corona's "physics" library local physics = require "physics"   --physics.setGravity(0, 9.2); physics.start(); --physics.pause();   --------------------------------------------   -- forward declarations and other locals local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth\*0.5, display.contentHeight\*0.5   ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --  -- NOTE: Code outside of listener functions (below) will only be executed once, --         unless storyboard.removeScene() is called. --  ----------------------------------------------------------------------------------------- -- Hide status bar ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar )     ----------------------------------------------------------------------------------------- -- Place the background ----------------------------------------------------------------------------------------- local background = display.newImage( "background.jpg");     background.anchorX = 0;     background.anchorY = 0;        -----------------------------------------------------------------------------------------     -- Creat "frog" ----------------------------------------------------------------------------------------- local frogBody = display.newRect ( 60, 275, 55, 35 );     frogBody:setFillColor( 0, 1, 0);      frogBody.strokeWidth = 3;     frogBody:setStrokeColor( 0, 0, 0 );     frogBody.rotation = -10;     ----------------------------------------------------------------------------------------- -- Creat "Lillypad" ----------------------------------------------------------------------------------------- local lillypad = display.newRect ( 60, 305, 80, 10 );     lillypad:setFillColor( 0, .6, 0);     lillypad.strokeWidth = 1;     lillypad:setStrokeColor( 0, 0, 0 );       ----------------------------------------------------------------------------------------- -- add physics to the frogbody, Lilypad ----------------------------------------------------------------------------------------- physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );   physics.addBody( lillypad, "static", { density=1.0, friction=0.3, bounce=.2 } )     local function moveFrog( event )       if  event.numTaps == 2  then         --code executed when the frog is double tapped         frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     end     return true  --prevents touch propagation to underlying objects end     frogBody:addEventListener( "tap", moveFrog )  --add a "touch" listener to the frog body

Hello.

So that doesn’t quite do it. Instead of taping a second time to get more height; that made so you have to tape it twice to get it to jump at all.

  -- -- Main.lua -- -----------------------------------------------------------------------------------------   -- include Corona's "physics" library local physics = require "physics"   --physics.setGravity(0, 9.2); physics.start(); --physics.pause();   --------------------------------------------   -- forward declarations and other locals local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth\*0.5, display.contentHeight\*0.5   ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --  -- NOTE: Code outside of listener functions (below) will only be executed once, --         unless storyboard.removeScene() is called. --  ----------------------------------------------------------------------------------------- -- Hide status bar ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar )     ----------------------------------------------------------------------------------------- -- Place the background ----------------------------------------------------------------------------------------- local background = display.newImage( "background.jpg");     background.anchorX = 0;     background.anchorY = 0;        -----------------------------------------------------------------------------------------     -- Creat "frog" ----------------------------------------------------------------------------------------- local frogBody = display.newRect ( 60, 275, 55, 35 );     frogBody:setFillColor( 0, 1, 0);      frogBody.strokeWidth = 3;     frogBody:setStrokeColor( 0, 0, 0 );     frogBody.rotation = -10;     ----------------------------------------------------------------------------------------- -- Creat "Lillypad" ----------------------------------------------------------------------------------------- local lillypad = display.newRect ( 60, 305, 80, 10 );     lillypad:setFillColor( 0, .6, 0);     lillypad.strokeWidth = 1;     lillypad:setStrokeColor( 0, 0, 0 );       ----------------------------------------------------------------------------------------- -- add physics to the frogbody, Lilypad ----------------------------------------------------------------------------------------- physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );   physics.addBody( lillypad, "static", { density=1.0, friction=0.3, bounce=.2 } )     local function moveFrog( event )     frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     if (event.phase == numTaps == 2 then         --code executed when the frog is touched         frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     end     return true  --prevents touch propagation to underlying objects end     frogBody:addEventListener( "tap", moveFrog )  --add a "touch" listener to the frog body

That doesn’t work either. It’s the same as the original version.

try this

http://aabweber.com/corona/how-jump-is-works-run-rabbit-run/

Thanks for the link, but that doesn’t make much sense to me.

I’m thinking I need to do something like remove the listener, and then put it back again.

no idea how to do this

use the tap event instead of touch

http://docs.coronalabs.com/api/event/tap/index.html

Hello Jstrahan.

Thanks for the input but I tried that already That doesn’t work…

should I use it all the time. post the code your using with it I’ll see if I can help

Thanks.

Here’s what I have so far (not much):

– Main.lua


– include Corona’s “physics” library

local physics = require “physics”

–physics.setGravity(0, 9.2);

physics.start(); --physics.pause();


– forward declarations and other locals

local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth*0.5, display.contentHeight*0.5


– BEGINNING OF YOUR IMPLEMENTATION

– 

– NOTE: Code outside of listener functions (below) will only be executed once,

–         unless storyboard.removeScene() is called.

– 


– Hide status bar


display.setStatusBar( display.HiddenStatusBar )


– Place the background


local background = display.newImage( “background.jpg”);

    background.anchorX = 0;

    background.anchorY = 0;

    

-----------------------------------------------------------------------------------------    

– Creat “frog”


local frogBody = display.newRect ( 60, 275, 55, 35 );

    frogBody:setFillColor( 0, 1, 0); 

    frogBody.strokeWidth = 3;

    frogBody:setStrokeColor( 0, 0, 0 );

    frogBody.rotation = -10;


– Creat “Lillypad”


local lillypad = display.newRect ( 60, 305, 80, 10 );

    lillypad:setFillColor( 0, .6, 0);

    lillypad.strokeWidth = 1;

    lillypad:setStrokeColor( 0, 0, 0 );


– add physics to the frogbody, Lilypad


physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );

physics.addBody( lillypad, “static”, { density=1.0, friction=0.3, bounce=.2 } )

local function moveFrog( event )

    if ( event.phase == “began” ) then

        --code executed when the frog is touched

        frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )

    end

    return true  --prevents touch propagation to underlying objects

end

frogBody:addEventListener( “touch”, moveFrog )  --add a “touch” listener to the frog body

-- -- Main.lua -- -----------------------------------------------------------------------------------------   -- include Corona's "physics" library local physics = require "physics"   --physics.setGravity(0, 9.2); physics.start(); --physics.pause();   --------------------------------------------   -- forward declarations and other locals local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth\*0.5, display.contentHeight\*0.5   ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --  -- NOTE: Code outside of listener functions (below) will only be executed once, --         unless storyboard.removeScene() is called. --  ----------------------------------------------------------------------------------------- -- Hide status bar ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar )     ----------------------------------------------------------------------------------------- -- Place the background ----------------------------------------------------------------------------------------- local background = display.newImage( "background.jpg");     background.anchorX = 0;     background.anchorY = 0;        -----------------------------------------------------------------------------------------     -- Creat "frog" ----------------------------------------------------------------------------------------- local frogBody = display.newRect ( 60, 275, 55, 35 );     frogBody:setFillColor( 0, 1, 0);      frogBody.strokeWidth = 3;     frogBody:setStrokeColor( 0, 0, 0 );     frogBody.rotation = -10;     ----------------------------------------------------------------------------------------- -- Creat "Lillypad" ----------------------------------------------------------------------------------------- local lillypad = display.newRect ( 60, 305, 80, 10 );     lillypad:setFillColor( 0, .6, 0);     lillypad.strokeWidth = 1;     lillypad:setStrokeColor( 0, 0, 0 );       ----------------------------------------------------------------------------------------- -- add physics to the frogbody, Lilypad ----------------------------------------------------------------------------------------- physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );   physics.addBody( lillypad, "static", { density=1.0, friction=0.3, bounce=.2 } )     local function moveFrog( event )       if  event.numTaps == 2  then         --code executed when the frog is double tapped         frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     end     return true  --prevents touch propagation to underlying objects end     frogBody:addEventListener( "tap", moveFrog )  --add a "touch" listener to the frog body

Hello.

So that doesn’t quite do it. Instead of taping a second time to get more height; that made so you have to tape it twice to get it to jump at all.

  -- -- Main.lua -- -----------------------------------------------------------------------------------------   -- include Corona's "physics" library local physics = require "physics"   --physics.setGravity(0, 9.2); physics.start(); --physics.pause();   --------------------------------------------   -- forward declarations and other locals local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth\*0.5, display.contentHeight\*0.5   ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --  -- NOTE: Code outside of listener functions (below) will only be executed once, --         unless storyboard.removeScene() is called. --  ----------------------------------------------------------------------------------------- -- Hide status bar ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar )     ----------------------------------------------------------------------------------------- -- Place the background ----------------------------------------------------------------------------------------- local background = display.newImage( "background.jpg");     background.anchorX = 0;     background.anchorY = 0;        -----------------------------------------------------------------------------------------     -- Creat "frog" ----------------------------------------------------------------------------------------- local frogBody = display.newRect ( 60, 275, 55, 35 );     frogBody:setFillColor( 0, 1, 0);      frogBody.strokeWidth = 3;     frogBody:setStrokeColor( 0, 0, 0 );     frogBody.rotation = -10;     ----------------------------------------------------------------------------------------- -- Creat "Lillypad" ----------------------------------------------------------------------------------------- local lillypad = display.newRect ( 60, 305, 80, 10 );     lillypad:setFillColor( 0, .6, 0);     lillypad.strokeWidth = 1;     lillypad:setStrokeColor( 0, 0, 0 );       ----------------------------------------------------------------------------------------- -- add physics to the frogbody, Lilypad ----------------------------------------------------------------------------------------- physics.addBody( frogBody, { density=.85, friction=.35, bounce=0 } );   physics.addBody( lillypad, "static", { density=1.0, friction=0.3, bounce=.2 } )     local function moveFrog( event )     frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     if (event.phase == numTaps == 2 then         --code executed when the frog is touched         frogBody:applyForce( 1000, 1990, frogBody.x, frogBody.y )     end     return true  --prevents touch propagation to underlying objects end     frogBody:addEventListener( "tap", moveFrog )  --add a "touch" listener to the frog body