在Corona SDK的Storyboard中,图像无法显示。

我正在使用corona SDK创作游戏,但是我遇到了一点问题。我有一个带有按钮的菜单,当我按下按钮时,它会将我发送到游戏的第一关。当我通过最后一关时,游戏会将我送回到菜单。但是,如果我再次开始玩的第一关,我的图像就不会出现了。

这些图像是球,要通过关卡,您必须消除所有的球。为了做到这一点,我使用了:

ball:removeSelf() ball = nil

但是,我认为这不是问题,因为即使我删除这些代码,它也不起作用。这些图像在scene:createScene函数中创建,并插入到组中。

我缩短了第一关的代码以便更容易理解。

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

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

physics.setGravity(0, 0)

local cont = 0
local bur = {}

function eliminar1(event)
  if (cont == 0) and (event.phase == "began") then
    event.target:removeSelf()
    bur[1] = nil
    cont = cont + 1
  end
end

function eliminar2(event)
  if (cont == 1) and (event.phase == "began") then
    bur[2]:removeSelf()
    bur[2] = nil
    cont = cont + 1
  end
end

function eliminar3(event)
  if (cont == 2) and (event.phase == "began") then
    bur[3]:removeSelf()
    bur[3] = nil
    storyboard.gotoScene("levels.1.level2")
  end
end

function scene:createScene(event)
  local screenGroup = self.view

  for i = 1, 3 do
    bur[i] = display.newImage("irudiak/" .. i .. ".png")
    bur[i]:translate(math.random(0, 280), math.random(0, 400))
    physics.addBody(bur[i], {bounce = 0.3})
    bur[i]:setLinearVelocity(math.random(-50, 50), math.random(-50, 50))
    screenGroup:insert(bur[i])
  end

  bur[1]:addEventListener("touch", eliminar1)
  bur[2]:addEventListener("touch", eliminar2)
  bur[3]:addEventListener("touch", eliminar3)
end

function scene:enterScene(event)
  local screenGroup = self.view

  physics.start()
end

function scene:exitScene(event)
  local screenGroup = self.view

  physics.stop()
end

function scene:destroyScene(event)
  local screenGroup = self.view

  package.loaded[physics] = nil
  physics = nil
end

return scene
点赞
用户2799485
用户2799485

createScene 仅在您首次 gotoScene 时运行。 每次之后只会执行 willEnterSceneenterScene。 要再次运行 createScene,您必须将其删除(storyboard.removeScene())。

或者,您可以将一些需要的内容移动到 willEnterScene。 要获取更详细的信息,请查看网址:http://www.coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

2013-09-20 14:04:27