2017-10-17 5 views
0

je suis nouveau ici, je suis en train de faire un jeu vidéo pour Android avec sdk couronne, mais je suis coincé avec la création de particules au hasard sur le fond, est le code ici:Impossible de reculer le groupe! Corona 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 wich call 'generateParticles' for each ms 


     smallPTimer=timer.performWithDelay(1, generateParticlesSmall, 0) 
     -- Start the timer wich call '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 

Toutes les fonctions fonctionnent parfaitement, mais le problème est que je ne peux pas reculer le groupe de particules, entre bg et sceneGroup.

Merci de m'écouter.

Répondre

0

Dans votre code, vous avez seulement 1 groupe d'affichage.

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

Vous devez créer particlesGroup comme enfant pour le ramener:

Déclare des variables locales sur le haut du fichier:

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

Créer des groupes dans 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