scrollview corona sdk - 从中​​拖出对象时不显示

时间:2014-12-28 05:19:25

标签: android ios uiscrollview lua corona

伙伴,我需要帮助在corona sdk中使用scrollview,在corona sdk中使用它是新的..

我试图在这里制作一些简单的益智游戏

所以这里我们去代码:

local widget = require("widget")

_W = display.contentWidth -- Get device screen width
_H = display.contentHeight -- Get device screen height
imgPiece = 3
imgPieces = {} 
imgPieceStartingY = { 80,230,380 }
imgPieceWidth, imgPieceHeight = 120, 120

-- Get some background image here
bg = display.newImageRect("bg.png", _W, _H)
bg.x = _W/2
bg.y = _H/2

-- Create some scrollview
scrollView = widget.newScrollView{ 
    top=100, 
    left = _W/2,
    height=_H/2,
    width = 160,
    hideBackground = true, 
    scrollWidth = 50 ,
    scrollHeight = 1000 }

-- Set image inside the scrollview
for i = 1, imgPiece do      
   imgPieces[i] = display.newImageRect("s"..i..".jpg", imgPieceWidth, imgPieceHeight)
   imgPieces[i].x = 85 -- Set Starting X position for img piece
   imgPieces[i].y = imgPieceStartingY[i] -- Set Starting Y position for img piece
   imgPieces[i].id = i
   imgPieces[i].place = "start"
   scrollView:insert(imgPieces[i])
end
问题是,当我尝试从滚动视图中拖出图像时,图像会消失。

当用户仍在拖动并按住图像时,当对象离开滚动视图边界框(我设置为160宽度)时,如何使图像仍然可见?

THX

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我在“开始”阶段用插入主组的图像解决了。

local function dragElements(event)
    local phase   = event.phase
    local obj     = event.target


    if phase == "began" then
        display.getCurrentStage():setFocus(obj)

        grp:insert(obj)
        obj.StartMoveX = event.x
        obj.StartMoveY = event.y

    elseif phase == "moved" then

        obj.x = (event.x - event.xStart) + obj.StartMoveX
        obj.y = (event.y - event.yStart) + obj.StartMoveY

    elseif phase == "ended" or phase == "canceled" then
        display.getCurrentStage():setFocus(nil)
    end

    return true
end