Lua 科罗纳/卢阿';轻触';跳跃

Lua 科罗纳/卢阿';轻触';跳跃,lua,coronasdk,Lua,Coronasdk,我在科罗纳运动有问题。我已经把它设置好了,这样我的角色就可以左右跑动了,但是现在我试着让它这样,当你点击他时,他会跳起来。我无法让代码正常工作 代码: “点击”事件没有event.phase字段。因此,如果您删除event.phase==“begined”检查,我认为它会起作用。“tap”事件没有event.phase字段。因此,如果您删除event.phase==“begined”检查,我认为它会起作用。“tap”事件没有event.phase字段。因此,如果您删除event.phase==“

我在科罗纳运动有问题。我已经把它设置好了,这样我的角色就可以左右跑动了,但是现在我试着让它这样,当你点击他时,他会跳起来。我无法让代码正常工作

代码:

“点击”事件没有event.phase字段。因此,如果您删除event.phase==“begined”检查,我认为它会起作用。

“tap”事件没有event.phase字段。因此,如果您删除event.phase==“begined”检查,我认为它会起作用。

“tap”事件没有event.phase字段。因此,如果您删除event.phase==“begined”检查,我认为它会起作用。

“tap”事件没有event.phase字段。所以,如果您删除event.phase==“begined”检查,我认为它会起作用

---------------------------------------------------------------------------------
-- CHARACTER PROPERTIES
---------------------------------------------------------------------------------

display.setDefault("magTextureFilter", "nearest")

local options =
{   --required parameters
    width = 32,
    height = 32,
    numFrames = 20,

    --optional parameters; used for dynamic resolution support
    sheetContentWidth = 160,  -- width of original 1x size of entire sheet
    sheetContentHeight = 128   -- height of original 1x size of entire sheet
}

local sheetAsh = graphics.newImageSheet( "boy.png", options )

local sequenceData =
{
    { name="down_stand", start=1, count=1},
    { name="down_run", frames={2, 3, 4, 5}, time=400, loopCount=0,  loopDirection = "bounce"},
    { name="left_stand", start=6, count=1},
    { name="left_run", frames={7, 8, 9, 10}, time=800, loopCount=0, loopDirection = "bounce"},
    { name="up_stand", start=11, count=1},
    { name="up_run", frames={12, 13, 14, 15}, time=1000, loopCount=0,  loopDirection = "bounce"},
    { name="right_stand", start=16, count=1},
    { name="right_run", frames={17, 18, 19, 20}, time=800, loopCount=0, loopDirection = "bounce"},
}

local spriteAsh = display.newSprite( sheetAsh, sequenceData )

physics.addBody(spriteAsh, "dynamic", {density =1.5 , bounce = 0.5, radius = 28})
spriteAsh.x = _W * 0.5
spriteAsh.y = _H * 0.5
spriteAsh.xScale = 2
spriteAsh.yScale = 2
spriteAsh.linearDamping = 2
--spriteAsh.gravityScale = 0.1

--spriteAsh:setSequence( "down_run" )
--spriteAsh:play()

local touchX, touchY

local touchScreen = function(e)
    --print(e.phase, e.x, e.y)
    if e.phase == "began" then
        touchX = e.x
        touchY = e.y
    elseif e.phase == "moved" then
        --spriteAsh.x = spriteAsh.x + (e.x - touchX)
        --spriteAsh.y = spriteAsh.y + (e.y - touchY)
        local difX = e.x - touchX
        local difY = e.y - touchY

        spriteAsh:applyForce(difX *50, 0, spriteAsh.x, spriteAsh.y)

        touchX = e.x
        touchY = e.y
    elseif e.phase == "ended" then

    end

end







local function jumptouch( event )
        if ( event.phase == "began" ) then
                spriteAsh:applyForce( 250, -1500, spriteAsh.x, spriteAsh.y )
        end
        return true
end

local function onScreenTouch( event )
        if event.phase == "began" then
                -- make character jump forward
                -- character:applyForce( 15000, -2500, character.x, character.y )
                --if event.xStart == character.x then
                        spriteAsh:applyForce( 250, -1500, spriteAsh.x, spriteAsh.y )
                --end
        end

        return true
end


spriteAsh:addEventListener( "tap", jumptouch, )