File &引用;扔;电晕SDK中的概念

File &引用;扔;电晕SDK中的概念,file,sdk,lua,coronasdk,File,Sdk,Lua,Coronasdk,好的,我正在创建一个应用程序,我已经创建了触摸和拖动效果。我不知道如何对用户释放对象并使其飞行的部分进行编码,因此称为“投掷” 再一次,我试图让用户能够抛出对象,而不是仅仅拖动它。此外,如果有人能帮助触摸并保持计时器,使物体离开并重生,那将不胜感激。您可能会计算释放时的速度:计算触摸开始阶段的触摸位置(x1,y1)和触摸结束阶段的触摸位置(x2,y2),以及两者之间的时间:然后通过object.setLinearVelocity()将对象的线速度设置为该值(这是一个2D向量)。如果主体是非静态的

好的,我正在创建一个应用程序,我已经创建了触摸和拖动效果。我不知道如何对用户释放对象并使其飞行的部分进行编码,因此称为“投掷”


再一次,我试图让用户能够抛出对象,而不是仅仅拖动它。此外,如果有人能帮助触摸并保持计时器,使物体离开并重生,那将不胜感激。

您可能会计算释放时的速度:计算触摸开始阶段的触摸位置(x1,y1)和触摸结束阶段的触摸位置(x2,y2),以及两者之间的时间:然后通过
object.setLinearVelocity()
将对象的线速度设置为该值(这是一个2D向量)。如果主体是非静态的,这将使其处于运动状态。运动将取决于它是动态的还是运动学的。如果是动态的,将设置速度,然后速度将根据应用于对象的外力(如重力)而变化。例如:

local startTouchMove = 0

....

local function touchListener(event)

    if event.phase == "began" then
        ...
        self.markX = event.x    -- store x location of object
        self.markY = event.y    -- store y location of object
        startTouchMove = system.timer()
        ...

    elseif self.isFocus then
        if event.phase == "moved" then
            ...

        elseif event.phase == "ended" then
            -- set the instantaneous velocity based on touch motion
            local dt = system.timer() - startTouchMove 
            if dt ~= 0 then                  
                local velX = ( event.x - self.markX ) / dt
                local velY = ( event.y - self.markY ) / dt
                yourObject:setLinearVelocity(velX, velY)        
            end
        end
    end 
end
local startTouchMove = 0

....

local function touchListener(event)

    if event.phase == "began" then
        ...
        self.markX = event.x    -- store x location of object
        self.markY = event.y    -- store y location of object
        startTouchMove = system.timer()
        ...

    elseif self.isFocus then
        if event.phase == "moved" then
            ...

        elseif event.phase == "ended" then
            -- set the instantaneous velocity based on touch motion
            local dt = system.timer() - startTouchMove 
            if dt ~= 0 then                  
                local velX = ( event.x - self.markX ) / dt
                local velY = ( event.y - self.markY ) / dt
                yourObject:setLinearVelocity(velX, velY)        
            end
        end
    end 
end