【发布时间】:2016-04-24 19:34:03
【问题描述】:
情况是这样的。只要我触摸屏幕,我就希望一个方形物体在 y 方向上不断移动。根据代码,我应该给我一个正方形对象的连续移动,但是,只有当我用手指在触摸屏上滑动时,对象才会移动。当我在同一个位置触摸屏幕时,我希望方形对象不断移动。
我尝试同时使用计时器和运行时事件侦听器,但均无济于事。这里有什么解决方法?
_W = display.contentWidth
_H = display.contentHeight
local background = display.newRect(0,0,_W,_H)
background.anchorX = 0
background.anchorY = 0
local squareTimer
local function squareMoveUp()
square.y = square.y - 5
end
local holding = 'false'
local function startMove(event)
if event.phase == 'began' then
--Runtime:addEventListener('enterFrame',squareMoveUp)
squareTimer = timer.performWithDelay(200,squareMoveUp,0)
elseif event.phase == 'ended' then
--Runtime:removeEventListener('enterFrame',squareMoveUp)
end
return true
end
background:addEventListener('touch',squareMoveUp)
【问题讨论】:
-
background应该全屏显示。 -
是的。我只是没有包含该代码。