【问题标题】:Image rotate and show transition in Corona SDKCorona SDK 中的图像旋转和显示过渡
【发布时间】:2013-03-26 00:21:11
【问题描述】:

我正在尝试点击屏幕并让我的坦克桶旋转到我点击的位置。我现在已经让那段代码可以工作了。我尝试做的下一步是假设我的坦克桶指向右侧,如果我点击左侧,我的坦克桶将立即旋转到左侧。我希望我的坦克枪管从右侧过渡到左侧,这样我们就可以看到运动/运动发生了,而不是它只是从右到左出现。

所以我再次希望看到坦克炮管实际上从右到左旋转/过渡,而不是它只是从右侧消失并重新出现在左侧(我试图模仿坦克炮管的真实旋转)。

点击屏幕和坦克桶指向那个方向的代码如下(还有一个代码在其中实现,如果我单击并按住,然后我可以将我的坦克桶拖到我试图的所需位置摆脱,我只想让它点击并过渡到现在)。

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

【问题讨论】:

    标签: image object rotation transition coronasdk


    【解决方案1】:

    这可能对你有帮助...

    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)
    

    继续编码...... :)

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 1970-01-01
      • 2015-09-02
      • 2016-02-12
      • 1970-01-01
      • 2011-09-08
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多