我是 Corona 的新手,我正在尝试按照本教程使用触摸在屏幕上拖动对象。
http://thatssopanda.com/corona-sdk-tutorials/dragging-an-object-in-corona-sdk/
我使用了几乎完全相同的代码,只是变量名称不同,并且是矩形而不是圆形,但我不断收到上述错误。
有任何想法吗?错误:
(文件:/Users/paulbyrne/Desktop/Transition/main.lua 行:6
尝试索引全局“矩形”(零值)
堆栈回溯:[C]:?/Users/paulbyrne/Desktop/Transition/main.lua:6:在主块中)
local rectangleShape = display.newRect( 100, 100, 100, 100 )
rectangleShape:setFillColor( 255, 255, 255 )
function rectangle:touch( event)
if event.phase == "began" then
display.getCurrentStage():setFocus( self, event.id)
self.isFocus = true
self.markX = self.x
self.markY = self.y
elseif self.isFocus then
if event.phase == "moved" then
self.x = event.x - event.xStart + self.markX
self.y = event.y - event.yStart + self.markX
elseif event.phase == "ended" or event.phase == "cancelled" then
display.getCurrentStage():setFocus( self, nil )
self.isFocus = false
end
end
return true
end
rectangleShape:addEventListener( "touch", rectangle )