【问题标题】:Corona/LUA 'tap' to jumpCorona/LUA“点击”跳跃
【发布时间】:2014-01-18 02:26:31
【问题描述】:

我在电晕中的运动有问题。我已经设置好了,所以我的角色可以左右奔跑,但现在我正在努力做到这一点,所以当你点击他时,他会跳跃。我无法让代码工作。

代码:

---------------------------------------------------------------------------------
-- 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, )

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 2018-09-08
      相关资源
      最近更新 更多