(Corona SDK) 场景过渡未播放
2019-8-13 10:27:37
收藏:0
阅读:104
评论:1
在 Corona SDK 中,我有两个场景。我能够在它们之间切换,但第一个场景没有被卸载, 过渡(slideRight)没有播放。
我尝试将 Scene 1(Menu.Lua)的内容移到 Scene:Create 和 Scene:Show 部分之间,但是这没有产生任何效果。我尝试更改过渡和过渡时间,但这没有改变任何东西,也没有起作用。
Menu.Lua
local composer = require( "composer" )
local widget = require( "widget" )
local scene = composer.newScene()
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
-- Setup
function setup (x)
print ("Hello World! Main Reporting ##")
display.setDefault("background", 0.2, 0.2, 0.2)
local startimage = display.newImage ( x )
startimage.x = display.contentCenterX
startimage.y = display.contentCenterY
end
setup("ugh.jpeg")
-- Button
local options =
{
effect = "slideRight",
time = 400
}
-- Create the widget
local buttonhours = widget.newButton(
{
shape = "roundedrect",
fillColor = { default={ 0.2, 0.2, 0.2, 0.7 }, over={ 1, 0.2, 0.5, 1 } },
x = display.contentCenterX - 75,
y = display.contentCenterY,
width = 125,
height = 45,
id = "button1",
label = "工作时间",
font = "Courier New",
fontSize = 25,
labelColor = { default={ 1, 1, 0.95 }, over={ 0, 0, 0, 0.5 } },
onEvent = handleButtonhoursEvent
}
)
local function handleButtonCriteriaEvent( event )
if ( "ended" == event.phase ) then
print( "按钮 Criteria 被按下并释放" .. options.effect )
composer.gotoScene( "scenes.criteria", options )
end
end
-- Create the widget
local buttoncriteria = widget.newButton(
{
shape = "roundedrect",
fillColor = { default={ 0.2, 0.2, 0.2, 0.7 }, over={ 1, 0.2, 0.5, 1 } },
x = display.contentCenterX + 75,
y = display.contentCenterY,
width = 125,
height = 45,
id = "button2",
label = "准则",
font = "Courier New",
fontSize = 25,
labelColor = { default={ 1, 1, 0.95 }, over={ 0, 0, 0, 0.5 } },
onEvent = handleButtonCriteriaEvent
}
)
end
Criteria.Lua
local composer = require( "composer" )
local scene = composer.newScene()
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
display.setDefault("background", 0.2, 0.2, 0.2)
print ("Hello World! Criteria Reporting ##")
end
下面是我的控制台,正如您看到的,按钮被按下,我们进入了第二个场景,但第一个场景仍然加载,并且没有过渡效果
12:07:34.552 从加载项目:C:\Users\****\Documents\Corona Projects\Prototype
12:07:34.552 项目沙盒文件夹:C:\Users\****\AppData\Local\Corona Labs\Corona Simulator\Sandbox\prototype-97576B4B1F269609E1981E30ED94ADC3\Documents
12:07:34.566 Hello World! Main Reporting ##
12:07:35.820 按钮 Criteria 被按下并释放slideRight
12:07:35.820 Hello World! Criteria Reporting ##
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

如果你使用 Composer(Corona的官方内置场景),那么你应该阅读指南:https://docs.coronalabs.com/guide/system/composer/index.html
当你在Composer中加载一个新场景时,除非你将场景移除,否则所有先前的场景仍然保持可访问和存在于内存中。
在你的情况下,显示对象不移动的原因是因为你没有将它们插入到场景组中。如果你希望Corona自动处理你的显示对象,那么你必须将显示对象插入到显示组中,然后将这些显示组插入到场景组中,或者直接将显示对象插入到场景组中。
为了将某物插入到一个组中,你只需这样做:
sceneGroup:insert( buttonhours )你遇到的另一个错误是你有两个名为“buttonhours”的局部变量。当你创建第二个变量时,你就失去了对原始变量的引用。