从当前位置绕固定点旋转

时间:2015-03-02 05:36:36

标签: math lua rotation vectormath quadratic-curve

需要在固定点周围移动精灵。需要注意的是,动议应该从当前的位置开始。精灵。

偏移角度,即使用幻数,并不是真的这样做,因为如果精灵和固定点之间的距离发生变化,它会有所不同。

参考图片:

enter image description here


    local block1Texture = Texture.new("block1.png",true)
    local block1 = Bitmap.new(block1Texture)
    block1:setAnchorPoint(0.5,0.5)
    stage:addChild(block1)
    block1:setPosition(50,50)

    local block2Texture = Texture.new("block2.png",true)
    local block2 = Bitmap.new(block2Texture)
    block2:setAnchorPoint(0.5,0.5)
    stage:addChild(block2)
    block2:setPosition(350,450)

    local block3Texture = Texture.new("block3.png",true)
    local block3 = Bitmap.new(block3Texture)
    block3:setAnchorPoint(0.5,0.5)
    stage:addChild(block3)
    block3:setPosition(300,700)

    local timer = Timer.new(500, 1)

    local rotateAroundBlock = block2

    function getCharAngleFromRope(startX, startY, targetX, targetY)  
        local xdiff = targetX - startX
        local ydiff = targetY - startY
            local ang = math.atan2( ydiff, xdiff )
        ang = math.deg(ang) + 90.0
        if ang =application:getDeviceWidth()) then
            --print("1")
            --px = block3:getX()
        end

        if(py=application:getContentHeight()) then
            --print("2")
            --py = block3:getY()
            --px = block3:getX()
        end

        block3:setPosition(px,py)
    end
    dist = math.sqrt((rotateAroundBlock:getX()-block3:getX())^2+(rotateAroundBlock:getY()-block3:getY())^2)
    angle = getCharAngleFromRope(block3:getX(),block3:getY(),rotateAroundBlock:getX(),rotateAroundBlock:getY())
    timer:addEventListener(Event.TIMER_COMPLETE, onTimerComplete)

    function startMoving()
        timer:start()
    end
    stage:addEventListener(Event.TOUCHES_BEGIN, startMoving)

1 个答案:

答案 0 :(得分:0)

解决。对于其他任何绊脚石的人来说,参数值需要是弧度而不是math.cos和math.sin的度数。像魅力一样。