Removing images and audio in Composer

Hi all,

First of all, thank you for taking the time to help me with, what I’m sure, is a very easy thing, however, I’ve looked through a ton of code and youtube videos, and cant seem to work this out, so, I’m now asking the wonderful forum if they can help :slight_smile:

I’m trying to code something from scratch and have found some amazing tutorials online - what I’m trying to do is, on the main page have 2 buttons, one with:

1: play with audio

2: play without audio

I haven’t actually coded the above yet, simply because I wanted to get each page’s bare bones working first.

From the code below I have made 2 pages, on one page there are audio play/pause/stop/rewind, which (unbelievably) works, however, the problem is, when you go to the next page, they stay on screen - I think I need to put in a way to ‘destroy’ the audio and images, however, I cant work it out.

Again, apologies if this is a really basic question, however, you will be a LEGEND if you can suggest a way I remove the buttons when navigating to a new screen :slight_smile:

Thank you all and have a great day, code below (attached).

Chris

you should place your audio buttons in scene:create function and add them all in sceneGroup… this will tell corona that the audio buttons belongs to mazda.lua scene and it will remove that buttons when going to other scene

So you code should look like this 

-- mazda.lua function scene:create( event ) local sceneGroup = self.view bg = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) bg:setFillColor(1,1,1) sceneGroup: insert(bg) title = display.newText("MAZDA", display.contentCenterX, display.contentCenterY, "Arial", 60) title:setFillColor(0,0,1) sceneGroup:insert(title) button = display.newRect(display.contentCenterX, display.contentHeight\*.9, display.contentWidth\*.2, display.contentHeight\*.05) button:setFillColor(1,0,0) sceneGroup:insert(button) playButton = display.newImage(sceneGroup,"play.png") playButton.x, playButton.y = display.contentCenterX, display.contentCenterY pauseButton = display.newImage(sceneGroup,"pause.png") pauseButton.x, pauseButton.y = display.contentCenterX, display.contentCenterY pauseButton.alpha = 0 stopButton = display.newImage(sceneGroup,"stop.png") stopButton.x, stopButton.y = display.contentWidth\*.8, display.contentCenterY rewindButton = display.newImage(sceneGroup,"rewind.png") rewindButton.x, rewindButton.y = display.contentWidth\*.2, display.contentCenterY button:addEventListener("tap", changeScenes) playButton:addEventListener("tap", playAudio) pauseButton:addEventListener("tap", pauseAudio) stopButton:addEventListener("tap", stopAudio) rewindButton:addEventListener("tap", rewindAudio) -- Code here runs when the scene is first created but has not yet appeared on screen end

Hope it helps you 

Akash :) 

Hi Akash,

Thank you so much for the above, I would have NEVER worked that out, and its also made lots of other things MUCH more clearer now.

Thank you very very much for your help - you’re an absolute legend :slight_smile:

Cheers,

Chris :slight_smile:

Glad it helped :D 

Cheers

you should place your audio buttons in scene:create function and add them all in sceneGroup… this will tell corona that the audio buttons belongs to mazda.lua scene and it will remove that buttons when going to other scene

So you code should look like this 

-- mazda.lua function scene:create( event ) local sceneGroup = self.view bg = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) bg:setFillColor(1,1,1) sceneGroup: insert(bg) title = display.newText("MAZDA", display.contentCenterX, display.contentCenterY, "Arial", 60) title:setFillColor(0,0,1) sceneGroup:insert(title) button = display.newRect(display.contentCenterX, display.contentHeight\*.9, display.contentWidth\*.2, display.contentHeight\*.05) button:setFillColor(1,0,0) sceneGroup:insert(button) playButton = display.newImage(sceneGroup,"play.png") playButton.x, playButton.y = display.contentCenterX, display.contentCenterY pauseButton = display.newImage(sceneGroup,"pause.png") pauseButton.x, pauseButton.y = display.contentCenterX, display.contentCenterY pauseButton.alpha = 0 stopButton = display.newImage(sceneGroup,"stop.png") stopButton.x, stopButton.y = display.contentWidth\*.8, display.contentCenterY rewindButton = display.newImage(sceneGroup,"rewind.png") rewindButton.x, rewindButton.y = display.contentWidth\*.2, display.contentCenterY button:addEventListener("tap", changeScenes) playButton:addEventListener("tap", playAudio) pauseButton:addEventListener("tap", pauseAudio) stopButton:addEventListener("tap", stopAudio) rewindButton:addEventListener("tap", rewindAudio) -- Code here runs when the scene is first created but has not yet appeared on screen end

Hope it helps you 

Akash :) 

Hi Akash,

Thank you so much for the above, I would have NEVER worked that out, and its also made lots of other things MUCH more clearer now.

Thank you very very much for your help - you’re an absolute legend :slight_smile:

Cheers,

Chris :slight_smile:

Glad it helped :D 

Cheers