使用带有计时器的目录在 Corona SDK 中。

我正在尝试使用带有“Recipes”示例的目录.. 我有一个定时器问题

在我运行main.lua页面后, 它应该显示我的标志和欢迎信息,然后它应该转到介绍页面, 在那里我有一个屏幕来获取用户名称和手机号,仅在他第一次使用应用程序时保存到txt文件中,然后下一次它将检查该txt文件。

接下来,它将直接转到“菜单”页面,用户可以从中选择

我的问题是,在main.lua中使用定时器显示徽标,但该定时器仍在其他屏幕中工作。

Main.lua(代码)

_w = display.viewableContentWidth
_h = display.viewableContentHeight

local background = display.newRect(0,0,_w,_h)
background:setFillColor(234,234,234local obj = display.newImage(“ams_logo.jpg”)

--将对象居中
obj.x = display.contentWidth * 0.5
obj.y = display.contentHeight * 0.5

--将对象淡入到完全透明
local transition_id = transition.from(obj,{time = 2000,alpha = 0})

-- local textObject = display.newText(“欢迎来到AMS项目”,20,350,native.systemFont,24)
local textObject = display.newText(“欢迎来到AMS项目”,_w * 0.1,_h * 0.8,native.systemFont,24)
textObject:setTextColor(255,144,0local transition_id = transition.from(textObject,{time = 1500,alpha = 0})

函数changeScene(e)
    if(e.phase ==“ended”)then
        director:changeScene(e.target.scene)
    end

end

local director = require(“director”);
local mainGroup = display.newGroup();

mainGroup:insert(director.directorView);
display.setStatusBar(display.HiddenStatusBar)_W = display.contentWidth _H = display.contentHeight number = 0

function fn_counter()

directorchangeScene(“intro”);

end
计时器.performWithDelay(5500,fn_counter,0)

介绍.lua

    module(...,package.seeallfunction new()

    local introGroup = display.newGroup();

        local background = display.newImage(“graphics/intro_background.png”)

        local begin = display.newImage(“graphics/begin_button.png”)
        begin.x = 160;
        begin.y = 400;
        begin.scene =“menu”;

        introGroupinsertbackground);
        introGroupinsertbegin);

        beginaddEventListener(“touch”,changeScene);

    return introGroup;

end

请帮帮我。。

点赞
用户2186639
用户2186639

在这个函数中

timer.performWithDelay( 5500, fn_counter, 0 )

意味着每隔 5500 秒调用一次 fn_counter(),并且无限次数地执行(因为有 0 个参数)。你应该将其更改为

timer.performWithDelay( 5500, fn_counter, 1 )
2013-04-12 07:47:03
用户7480063
用户7480063

你是想要制造延迟吗? ...如果是的话,你可以使用 Lua 的 os.execute 函数,例如:

function delay(s)--我在 OS X 使用以下代码可以让程序延迟指定的秒数
os.execute("sleep "..s)
end

如果你使用目标操作系统客户端,你可以像在 Windows 的 cmd 或者 OS X 的 termanal 中一样使用它的命令行窗口。我知道 Corona 可以与这些操作系统一起使用。同时,我也因为你的问题没有给出太具体的帮助而抱歉。

2017-03-09 05:25:35