【问题标题】:storyboard.removeScene("scene name") is not workingstoryboard.removeScene(“场景名称”)不起作用
【发布时间】:2015-09-01 06:25:19
【问题描述】:

我是 corona sdk 的新手,并试图在其中构建示例。我想在一段时间后通过破坏我的场景自动返回主屏幕(我的意思是场景在某个特定时间后自行破坏,用户返回主屏幕)。我知道对于某些人来说这可能听起来很傻,但我是 Corona 的初学者

这是我的 main.lua 代码:-

local storyboard = require "storyboard"

local widget = require( "widget" )
--/**/ widget.setTheme( "widget_theme_android" )

local json = require "json"

local particleDesigner = require( "particleDesigner" )



local physics = require( "physics" )
physics.start()

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

local sky = display.newImage( "sky.jpg",contentCenterX,display.contentCenterY)



local emitter

		emitter = particleDesigner.newEmitter("air_stars.json")
		emitter.x = (contentCenterX)
		emitter.y = (contentCenterY)

local button = {}

y= -50

for count = 1,3 do
    y = y + 110
    x = 20

    for insideCount = 1,3 do
        x = x + 110

        button[count] = display.newImage("1.png")             

        button[count].x = x
        button[count].y = y   

        local container = display.newContainer( 0, 0 )
        container:translate(button[count].x-40, button[count].y-40)

        local bkgd = display.newImage( container, "2.png" )



        function buttonTap(self)
        button[count].touch = transition.to(container,{time=3000, height = button[count].height+x, width = button[count].width+y, onComplete = StartGame})

         function StartGame()
            storyboard.purgeScene("main")
              if count == 1 and insideCount == 1 then
                    storyboard:gotoScene("bridge")

                    elseif count == 1 and insideCount == 2 then

                        storyboard:gotoScene("Heli")
                end    
        end
        end

        button[count]:addEventListener( "touch", buttonTap)
    end
end
        return storyboard

这是我的 bridge.lua 文件:- (http://piratepad.net/ep/pad/view/ro.JR1Bpt1qkA$/latest)

任何帮助将不胜感激

谢谢

【问题讨论】:

  • 实际上我想要的是,当我点击特定按钮时,动画应该出现在我没有点击的那个按钮上,其次动画应该从按钮中间开始并慢慢覆盖按钮的整个高度和宽度

标签: android gridview lua coronasdk


【解决方案1】:

嗨,你好:

_W = display.contentWidth;
_H = display.contentHeight;

local button = {}

x = -20

for count = 1,3 do
    x = x + 90
    y = 20

    for insideCount = 1,3 do
        y = y + 90

        button[count] = display.newImage("imgs/one.png");               

        button[count].x = x;
        button[count].y = y;    

        local container = display.newContainer( 0, 0 )
        container:translate(button[count].x, button[count].y)

        local bkgd = display.newImage( container, "imgs/two.png" )

        function buttonTap(self)
        button[count].touch = transition.to(container,{time=3000, height = button[count].height+x, width = button[count].width+y})
        end

        button[count]:addEventListener( "touch", buttonTap )
    end
end

只需将其添加到 bridge.lua

local function goBack()
    storyboard:gotoScene("buttons") 
end
timer.performWithDelay( 3000, goBack, 1 )

这个到 main.lua

storyboard.purgeOnSceneChange = true

【讨论】:

  • 谢谢凯文德...非常感谢您的帮助..:)
  • 凯文德可以再帮我一个忙....我正在尝试的是,当用户单击按钮时,我开始动画,并在完成此动画后,我会调用一个新功能,让用户进入新场景......(故事板:gotoScene(“桥”))但现在我想要的是一段时间后场景会自动删除或销毁,用户再次返回主屏幕......我尝试了场景:revofeself()..with scene.destroy()..但没有找到任何结果..所以你能告诉我什么应该是更好的方法.....
  • 没有。我问我想在特定时间间隔后销毁场景..您在代码中提到的上述部分是将用户带到下一个场景的代码(即在 bridge.lua 中)这部分是在我结束时完成的,但现在我希望这个场景在特定的时间间隔后被破坏,比如说 30 秒后这个场景应该被破坏(我的意思是桥场景)并且用户应该回到它的主屏幕(包含按钮的屏幕)。
  • 看看我编辑看看这是否适合你,ps建议将touch更改为tap
  • 感谢您的回复....但是我收到一个尝试调用方法'dispatchEvent'的错误(一个零值)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-13
  • 2016-12-21
  • 2017-07-09
  • 2016-03-11
  • 1970-01-01
相关资源
最近更新 更多