cocos2d-x中精灵移动

来源:互联网 发布:javascript var 数组 编辑:程序博客网 时间:2024/06/10 14:46

 local goRight =true--判断它移动的方向    local function update( )

 

        local x=text:getPosition()

        text:setScale(1.5-x/450)

        if goRight then 

            local x,y = text:getPosition()--得到当前的位置

            text:setPosition(cc.p(x+1,y))--向右走

            --判断它的位置是否大于可视区域width+text宽度/2的位置

            if text:getPosition()>origin.x+visibleSize.width-text:getContentSize().width/2*text:getScale() then

                goRight=false--如果大于,就让他走下面

            end

        else

            --同理

            local x,y = text:getPosition()

            text:setPosition(cc.p(x-1,y))

            if text:getPosition()

                goRight=true

            end

        end

 

 

 

0 0
原创粉丝点击