繁体   English   中英

图像旋转并在Corona SDK中显示过渡

[英]Image rotate and show transition in Corona SDK

我试图在屏幕上单击,并使我的油桶旋转到我单击的位置。 到目前为止,我已经获得了那段代码。 我要尝试做的下一步是假设例如我的油桶桶指向右侧,如果我单击左侧,我的油桶桶将立即旋转到左侧。 我希望我的油桶从右侧过渡到左侧,以便我们看到运动/运动发生了,而不是仅仅从右向左出现。

因此,我再次希望看到油桶实际上是从右向左旋转/过渡,而不是仅仅从右侧消失并重新出现在左侧(即试图模拟油桶的真实旋转)。

点击屏幕和坦克桶目标朝该方向的代码在下面(还有一个实现的代码,如果我单击并按住该代码,则可以将坦克桶拖到想要的位置,而我试图摆脱掉我只希望它点击并过渡到现在)。

local function rotateObj(event)
    local t = event.target
    local phase = event.phase
if event.y < 225 then        
    if (phase == "began") then
            display.getCurrentStage():setFocus( t )
            t.isFocus = true


    local diffX = tankbarrel.x - event.x
    local diffY = tankbarrel.y - event.y
  tankbarrel.rotation = math.atan2(diffY, diffX) / RADIANS_TO_DEGREES + 180          

            -- Store initial position of finger
            t.x1 = event.x
            t.y1 = event.y

    elseif t.isFocus then

            if (phase == "moved") then
                    t.x2 = event.x
                    t.y2 = event.y

                    angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
                    angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
                    print("angle1 = "..angle1)
                    rotationAmt = angle1 - angle2 

                    --rotate it 
                    tankbarrel.rotation = tankbarrel.rotation - rotationAmt
                    print ("tankbarrel.rotation = "..tankbarrel.rotation)

-- set limits to how far the barrel can rotate                    
if tankbarrel.rotation < 210 then 
                    tankbarrel.rotation = 209
                    end

                    if tankbarrel.rotation > 330 then
                        tankbarrel.rotation = 329
                        end

                    t.x1 = t.x2
                    t.y1 = t.y2

            elseif (phase == "ended") then

                    display.getCurrentStage():setFocus( nil )
                    t.isFocus = false
            end
    end
end
    -- Stop further propagation of touch event
    return true
end

这可能对您有帮助...

local tankbarrel = ..........  -- create your tank  

local function immediateTransRotation(e)
    if(e.x<tankbarrel.x)then
       transition.to(tankbarrel,{time=100,rotation=0})    -- rotate, if clicked on left side of the tank
    else
       transition.to(tankbarrel,{time=100,rotation=180})  -- rotate, if clicked on right side of the tank
    end
end
Runtime:addEventListener("tap",immediateTransRotation)

继续编码... :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM