android 无法向后移动组!Corona SDK

qq24tv8q  于 2023-05-15  发布在  Android
关注(0)|答案(1)|浏览(102)

我是新来的,我试图做一个视频游戏的Android与电晕SDK,但我坚持与创建随机粒子的背景,这里是代码:

local menu = composer.newScene()

function menu:create( event )
  local bg = self.view
  local particlesGroup = self.view
  local sceneGroup = self.view

  blackLayer = display.newImageRect(  "black_layer.png",  1280, 300 )
  blackLayer.y = display.contentCenterY + 150
  blackLayer.x = display.contentCenterX
  blackLayer.alpha = 0.6


  background = display.newImageRect( "background.png",  1280 , 720 )
  background.x = display.contentCenterX
  background.y = display.contentCenterY



  playBtn = widget.newButton( {
    id="playBtn",
    x=display.contentCenterX+350,
    y=blackLayer.y,
    labelColor = { default={0.922, 0.938, 0.941}, over={0.9, 0.3, 0.234, 0.6}},
    label = "Play Now",
    defaultFile = "redBtn.png",
    overFile = "whiteBtn.png",
    width = 200,
    height = 200,
    fontSize = 30,
    font = "Fonts/Raleway-Bold.ttf",
    --onRelease = composer.gotoScene( "game")
  } )

  settingsBtn = widget.newButton( {
      id="playBtn",
      x=display.contentCenterX,
      y=blackLayer.y-50,
      font = "Fonts/Raleway-Bold.ttf",
      label = "Settings",
      defaultFile = "rectWhiteBtn.png",
      overFile = "rectRedBtn.png",
      width =250,
      height = 100,
      fontSize = 30,
      labelColor = { default={0.9, 0.3, 0.234} , over={0.922, 0.938, 0.941, 0.6} },
      onRelease = gotoSettings
    } )

  highScoresBtn = widget.newButton( {
        id="highScoresBtn",
        x=display.contentCenterX,
        y=settingsBtn.y + 100,
        font = "Fonts/Raleway-Bold.ttf",
        label = "High Scores",
        defaultFile = "rectWhiteBtn.png",
        overFile = "rectRedBtn.png",
        width =250,
        height = 100,
        fontSize = 30,
        labelColor = { default={0.9, 0.3, 0.234} , over={0.922, 0.938, 0.941, 0.6} },
        --onRelease = composer.gotoScene("highScores")
      } )

      bg:insert(background)
      sceneGroup:insert(blackLayer)
      sceneGroup:insert(playBtn)
      sceneGroup:insert(settingsBtn)
      sceneGroup:insert(highScoresBtn)

      function generateParticles()
        local xy=math.random(30,70)
        local newParticle = display.newImageRect( particlesGroup,  objectSheet , math.random(13), xy, xy )
        newParticle.x = (math.random(1280)*math.random(88932))%1280
        newParticle.y = (math.random(720)*math.random(13546))%720
        newParticle.alpha = 0
        transition.to( newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
      end

      function generateParticlesSmall()
        local xy=math.random(5,15)
        local newParticle = display.newImageRect( particlesGroup,  objectSheet , 1, xy, xy )
        newParticle.x = (math.random(1280)*math.random(88932))%1280
        newParticle.y = (math.random(720)*math.random(13546))%720
        newParticle.alpha = 0
        transition.to( newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
      end

end

function menu:show( event )
  local bg = self.view
  local particlesGroup = self.view
  local sceneGroup = self.view
  local phase = event.phase


    if ( phase == "will" ) then

      bigPTimer1=timer.performWithDelay( 1, generateParticles, 0 )
      -- Start the timer which calls 'generateParticles' for each ms

      smallPTimer=timer.performWithDelay( 1, generateParticlesSmall, 0 )
      -- Start the timer which calls 'generateParticlesSmall' for each ms
      particlesGroup:toBack()

    elseif ( phase == "did" ) then

        if event.phase=="began"then
        end
        if event.phase=="ended"then
        end

    end
end

function menu:hide( event )
  local bg = self.view
  local particlesGroup = self.view
  local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)


    elseif ( phase == "did" ) then
        -- Code here runs when the scene is entirely on screen

    end
end

function menu:destroy( event )
  local bg = self.view
  local particlesGroup = self.view
  local sceneGroup = self.view
end

--Funzioni

local function gotoGame()
    composer.gotoScene( "game" )
end

local function gotoHighScores()
    composer.gotoScene( "highscores" )
end

function gotoSettings()
  reproduceEffet1()
  timer.cancel(bigPTimer1)
  timer.cancel(smallPTimer)
  composer.gotoScene( "settings", options)
end

--funzioni

local function removetotally( particle )
  display.remove( particle )
end

function dimParticle( particle )
    transition.to( particle, {alpha=0, time=500, onComplete = removetotally, onCompleteParams = particle})
end

--

menu:addEventListener( "create", menu )
menu:addEventListener( "show", menu )
menu:addEventListener( "hide", menu )
menu:addEventListener( "destroy", menu )

--

return menu

所有函数都运行得很好,但问题是我无法将粒子组移回bg和sceneGroup之间。
谢谢你听我说

k10s72fa

k10s72fa1#

在您的代码中,只有一个显示组。

local bg = self.view
local particlesGroup = self.view
local sceneGroup = self.view

您需要创建particlesGroup作为子节点,以便将其移回:
在文件顶部声明局部变量:

local menu = composer.newScene()
local bg, particlesGroup

menu:create中创建组

bg = display.newGroup()
particlesGroup = display.newGroup()
local sceneGroup = self.view
sceneGroup:insert(bg)
sceneGroup:insert(particlesGroup) -- here particlesGroup will be on the top

particlesGroup:toBack() --now particlesGroup is under bg

相关问题