在电晕中拖动对象

时间:2015-02-10 15:01:00

标签: corona

我有一个对象,我只想上下移动。如何在不实际接触物体的情况下使该物体仍然上下移动?到目前为止,这是我的代码:

function Scientist:touch( event )
if event.phase == "began" then

        display.getCurrentStage():setFocus(  nil)
         self.markY = self.y    
         self.isFocus = false
elseif event.phase == "moved" then

        local y = (event.y - event.yStart) + self.markY
        self.y = y

elseif event.phase == "ended"  or event.phase == "cancelled" then

        display.getCurrentStage():setFocus(nil)

end

        return true

end
        Scientist:addEventListener('touch', Scientist)

2 个答案:

答案 0 :(得分:0)

只需创建一个大矩形,将alpha设置为0,然后设置宽度display.contentWidth和高度display.contentHeight。当你触摸那个矩形时,让你以与现在类似的方式移动科学家。

答案 1 :(得分:0)

在整个页面上创建一个矩形,并将alpha设置为0.01:

local background = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight)

然后像你做background:addEventListener('touch', background)

那样写一个触控听众

这里有完整的代码:

function Scientist:touch( event )
  if event.phase == "began" then
         display.getCurrentStage():setFocus(  nil)
         Scientist.markY = Scientist.y    
         self.isFocus = false
  elseif event.phase == "moved" then    
        local y = (event.y - event.yStart) + Scientist.markY
        Scientist.y = y    
  elseif event.phase == "ended"  or event.phase == "cancelled" then    
        display.getCurrentStage():setFocus(nil)    
  end    
return true
end
Scientist:addEventListener('touch', Scientist)