Lua 无法使函数在Corona SDK中工作(使用TabButton)

Lua 无法使函数在Corona SDK中工作(使用TabButton),lua,coronasdk,Lua,Coronasdk,我对Corona SDK完全陌生,我只是查看示例项目,看看它们是如何工作的。我正在看TAB示例,但是我有一个问题 我有一个这样的页面,所以这是第2页 local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view

我对Corona SDK完全陌生,我只是查看示例项目,看看它们是如何工作的。我正在看TAB示例,但是我有一个问题

我有一个这样的页面,所以这是第2页

local composer = require( "composer" )
local scene = composer.newScene()

function scene:create( event )
    local sceneGroup = self.view

    -- Called when the scene's view does not exist.
    -- 
    -- INSERT code here to initialize the scene
    -- e.g. add display objects to 'sceneGroup', add touch listeners, etc.

    -- create a white background to fill screen (things go in here like pictures etc)
    local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
    bg.anchorX = 0
    bg.anchorY = 0
    bg:setFillColor( 0 )    -- white

    -- this will create the thing that you drag (the function is after)
    local tracker = display.newRect( 568, 340, 50, 50 )
    tracker:setFillColor( 1 )

    -- all objects must be added to group (e.g. self.view)
    sceneGroup:insert( bg )
    sceneGroup:insert( tracker )
end

function scene:show( event )
    local sceneGroup = self.view
    local phase = event.phase

    if phase == "will" then
        -- Called when the scene is still off screen and is about to move on screen
    elseif phase == "did" then
        -- Called when the scene is now on screen
        -- 
        -- INSERT code here to make the scene come alive
        -- e.g. start timers, begin animation, play audio, etc.
    end 
end

function scene:hide( event )
    local sceneGroup = self.view
    local phase = event.phase

    if event.phase == "will" then
        -- Called when the scene is on screen and is about to move off screen
        --
        -- INSERT code here to pause the scene
        -- e.g. stop timers, stop animation, unload sounds, etc.)
    elseif phase == "did" then
        -- Called when the scene is now off screen
    end
end

function scene:destroy( event )
    local sceneGroup = self.view

    -- Called prior to the removal of scene's "view" (sceneGroup)
    -- 
    -- INSERT code here to cleanup the scene
    -- e.g. remove display objects, remove touch listeners, save state, etc.
end

function tracker:touch( event )
    if event.phase == "began" then
        self.markX = self.x --stores x location
        self.markY = self.y --stores y location
    elseif event.phase == "moved" then
        local x = (event.x - event.xStart) + self.markX
        local y = (event.y - event.yStart) + self.markY
        self.x, self.y = x, y -- moves the object from things above
    end
end



---------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
tracker:addEventListneer( "touch", tracker)
-----------------------------------------------------------------------------------------

return scene
无论如何,为了简化工作,我所做的更改包括:

local tracker = display.newRect( 568, 340, 50, 50 )
tracker:setFillColor( 1 )
这将创建一个我正在尝试创建的新框,以便您可以在我使用此功能的屏幕上拖动它:

function tracker:touch( event )
    if event.phase == "began" then
        self.markX = self.x --stores x location
        self.markY = self.y --stores y location
    elseif event.phase == "moved" then
        local x = (event.x - event.xStart) + self.markX
        local y = (event.y - event.yStart) + self.markY
        self.x, self.y = x, y -- moves the object from things above
    end
end
所以总的来说,它创建了一个框,我正在尝试向其中添加一个函数,以便您可以在屏幕上拖动它。然而,它不工作,并给我一个错误,说,跟踪器上的功能线功能开始跟踪器:触摸事件是错误的?任何帮助,因为我认为这是在错误的地方

另外,我还有一个跟踪器:addEventListneer触摸,跟踪器侦听器

-感谢您将本地跟踪器创建为场景中的本地变量:create函数。这意味着该变量仅在所述函数的范围内可用

您需要将函数tracker:touchevent移动到场景:create函数中,以便可以访问该跟踪器


您需要将侦听器移动到场景底部:创建函数。

没关系。我已经修好了。我应该经常检查我的拼写xD,我拼写了tracker:addEventListener touch,tracker错了。这样一个错误。谢谢你们的帮助

哦,好的,谢谢。但是,它没有工作,因为我把跟踪器:addEventListneer touch,跟踪器放在场景中:create,但它仍然给我一个错误?我还在场景底部添加了return true:create。您需要链接错误。所有的错误都解释了问题所在,我们可以告诉你问题所在。