按钮工作然后失败

时间:2015-08-14 18:18:31

标签: button lua corona

我的问题非常混乱,我看来似乎没有一个简单的解决方案。当我进入我的设置'场景有两个按钮' aboutButton'和' userSettingsButton'这些按钮会导致称为“' about'和'用户'。在这个场景(查看,关于按钮和用户设置),我可以单击任一按钮,它响应我单击它的文本上的任何位置。在同一页面上,我有一个返回主页按钮也可以。当我点击“关于”按钮时,一切都按照正常情况进行,我会转到'该场景然后可以使用我的' goBackButton'在' about'场景,按钮​​停止工作。当我转到'我的用户'场景一切似乎都有效(包括那个场景上的' goBackButton')但是在我回到“设置场景”后#39;如果我试图重新回到“关于应用程序”的问题。或者'用户设置'我只能通过点击最上边缘(对于'关于应用程序')和用户设置'来激活该按钮。我只能通过点击应用程序的最底部来激活它。

我知道这似乎是一个非常奇怪的问题而且我在使用免费版Corona SDK的Windows机器上(如果该信息与它有任何关系)但是就像我说通常所有按钮都工作正常我的程序中只有文字按钮和“我的数据”按钮。 (替换为全局变量)用于我转到' '用户设置',请告诉我是否有任何其他信息我需要给别人帮助我这个程序所有的代码都不会引起任何错误。所有工作都很精细直到我输入用户设置,然后是那些工作之后的事情,其他人不会。

感谢您抽出宝贵时间阅读本文,感谢您对如何解决此问题提供任何帮助或建议。

我在想,这可能是一个与内存有关的问题..我将28个项目显示到我的sceneGroup中,所以请告诉我这个假设是否正确。

以下是设置主页的代码:

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

function scene:create ()
    local g = self.view
end

function returnHomeButtonOptions()
    local options = 
    {
    effect = "slideDown",
    time = 500,
    }
    composer.gotoScene("MainContent.HomeScreen", options)
end

function aboutButtonOptions()
    local options = 
    {
    effect = "slideUp",
    time = 500,
    }
    composer.gotoScene("MainContent.Settings.about", options)
end

function userButtonOptions()
    local options =
    {
    effect = "slideRight",
    time = 500,
    }
    composer.gotoScene("MainContent.Settings.user", options)
end

local function returnHomeButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        returnHomeButtonOptions()
    end
end

local function aboutButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        aboutButtonOptions()
    end
end

local function userButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        userButtonOptions()
    end
end

local returnHomeButton = widget.newButton
{
    label = "Return Home",
    x = display.contentWidth * 0.8125,
    y = display.contentWidth * 1.5625,
    onEvent = returnHomeButtonHandler,
    fontSize = 16,
    labelColor = { default={ 1, 1, 1 } }
}

local aboutButton = widget.newButton
{
    label = "About The App",
    x = display.contentWidth * 0.5,
    y = 150,
    onEvent = aboutButtonHandler,
    fontSize = 30,
    labelColor = { default={ 1, 1, 1 } }
}

local userButton = widget.newButton
{
    label = "User Settings",
    x = display.contentWidth * 0.5,
    y = 300,
    onEvent = userButtonHandler,
    fontSize = 30,
    labelColor = { default={ 1, 1, 1 } }
}


local backBlock = display.newRect(0, 0, display.contentWidth * 2, display.contentHeight * 3)
local block2 = display.newRect(display.contentWidth * 0.25, 100, 100, 100)
local block3 = display.newRect(display.contentWidth * 0.75, 100, 100, 100)
local block4 = display.newRect(display.contentWidth * 0.5, 10, 100, 100)
local block5 = display.newRect(display.contentWidth * 0.25, 200, 100, 100)
local block6 = display.newRect(display.contentWidth * 0.75, 200, 100, 100)
local block7 = display.newRect(display.contentWidth * 0.5, 490, 100, 100)
local block8 = display.newRect(display.contentWidth * 0.25, 300, 100, 100)
local block9 = display.newRect(display.contentWidth * 0.75, 300, 100, 100)
local block10 = display.newRect(display.contentWidth * 0.25, 400, 100, 100)
local block11 = display.newRect(display.contentWidth * 0.75, 400, 100, 100)
block2:rotate(45)
block3:rotate(45)
block4:rotate(45)
block5:rotate(45)
block6:rotate(45)
block7:rotate(45)
block8:rotate(45)
block9:rotate(45)
block10:rotate(45)
block11:rotate(45)
block2.alpha = 0.2
block3.alpha = 0.2
block4.alpha = 0.2
block5.alpha = 0.2
block6.alpha = 0.2
block7.alpha = 0.2
block8.alpha = 0.2
block9.alpha = 0.2
block10.alpha = 0.2
block11.alpha = 0.2
backBlock.alpha = 0.1

function scene:show (event)

    local g = self.view
    local phase = event.phase

    if (phase == "will") then

        display.setStatusBar( display.DarkStatusBar )

        g:insert(backBlock)
        g:insert(block2)
        g:insert(block3)
        g:insert(block4)
        g:insert(block5)
        g:insert(block6)
        g:insert(block7)
        g:insert(block8)
        g:insert(block9)
        g:insert(block10)
        g:insert(block11)
        g:insert(returnHomeButton)
        g:insert(aboutButton)
        g:insert(userButton)

    end
end


scene:addEventListener("create", scene)
scene:addEventListener("show", scene)



return scene

这是用户的代码

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

function scene:create ()
    local g = self.view
end

function returnHomeButtonOptions()
    local options = 
    {
    effect = "slideDown",
    time = 500,
    }
    composer.gotoScene("MainContent.HomeScreen", options)
end

function aboutButtonOptions()
    local options = 
    {
    effect = "slideUp",
    time = 500,
    }
    composer.gotoScene("MainContent.Settings.about", options)
end

function userButtonOptions()
    local options =
    {
    effect = "slideRight",
    time = 500,
    }
    composer.gotoScene("MainContent.Settings.user", options)
end

local function returnHomeButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        returnHomeButtonOptions()
    end
end

local function aboutButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        aboutButtonOptions()
    end
end

local function userButtonHandler(event)
    local phase = event.phase
    if (phase == "ended") then
        userButtonOptions()
    end
end

local returnHomeButton = widget.newButton
{
    label = "Return Home",
    x = display.contentWidth * 0.8125,
    y = display.contentWidth * 1.5625,
    onEvent = returnHomeButtonHandler,
    fontSize = 16,
    labelColor = { default={ 1, 1, 1 } }
}

local aboutButton = widget.newButton
{
    label = "About The App",
    x = display.contentWidth * 0.5,
    y = 150,
    onEvent = aboutButtonHandler,
    fontSize = 30,
    labelColor = { default={ 1, 1, 1 } }
}

local userButton = widget.newButton
{
    label = "User Settings",
    x = display.contentWidth * 0.5,
    y = 300,
    onEvent = userButtonHandler,
    fontSize = 30,
    labelColor = { default={ 1, 1, 1 } }
}


local backBlock = display.newRect(0, 0, display.contentWidth * 2, display.contentHeight * 3)
local block2 = display.newRect(display.contentWidth * 0.25, 100, 100, 100)
local block3 = display.newRect(display.contentWidth * 0.75, 100, 100, 100)
local block4 = display.newRect(display.contentWidth * 0.5, 10, 100, 100)
local block5 = display.newRect(display.contentWidth * 0.25, 200, 100, 100)
local block6 = display.newRect(display.contentWidth * 0.75, 200, 100, 100)
local block7 = display.newRect(display.contentWidth * 0.5, 490, 100, 100)
local block8 = display.newRect(display.contentWidth * 0.25, 300, 100, 100)
local block9 = display.newRect(display.contentWidth * 0.75, 300, 100, 100)
local block10 = display.newRect(display.contentWidth * 0.25, 400, 100, 100)
local block11 = display.newRect(display.contentWidth * 0.75, 400, 100, 100)
block2:rotate(45)
block3:rotate(45)
block4:rotate(45)
block5:rotate(45)
block6:rotate(45)
block7:rotate(45)
block8:rotate(45)
block9:rotate(45)
block10:rotate(45)
block11:rotate(45)
block2.alpha = 0.2
block3.alpha = 0.2
block4.alpha = 0.2
block5.alpha = 0.2
block6.alpha = 0.2
block7.alpha = 0.2
block8.alpha = 0.2
block9.alpha = 0.2
block10.alpha = 0.2
block11.alpha = 0.2
backBlock.alpha = 0.1

function scene:show (event)

    local g = self.view
    local phase = event.phase

    if (phase == "will") then

        display.setStatusBar( display.DarkStatusBar )

        g:insert(backBlock)
        g:insert(block2)
        g:insert(block3)
        g:insert(block4)
        g:insert(block5)
        g:insert(block6)
        g:insert(block7)
        g:insert(block8)
        g:insert(block9)
        g:insert(block10)
        g:insert(block11)
        g:insert(returnHomeButton)
        g:insert(aboutButton)
        g:insert(userButton)

    end
end


scene:addEventListener("create", scene)
scene:addEventListener("show", scene)



return scene

在那里你可以看到我的user.lua代码和settingsHome.lua

感谢您阅读并帮助我:)

1 个答案:

答案 0 :(得分:0)

尝试return true处理按钮操作的函数。