Hello,
Forgive me if this has been asked before, but I didn’t find it on the search.
I’m working on my App. The App got a main.lua , view1.lua and view2.lua. In view1 a image is loaded in the view. And when the user pressed the image, the image will change to a new image and play a sound. That’s works fine.
But, the problem. When the user tapped on the view2 tap (this will load a new view) The image is still visible in view2.
How do I remove the image from view2? But When the user tapped to view1 the image must be visible and working.
Code view1:
Cheers,
Alwin
[code]-----------------------------------------------------------------------------------------
– view1.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– BEGINNING OF YOUR IMPLEMENTATION
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– create a white background to fill screen
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg:setFillColor( 255 ) – white
– Load picture
local picture_sound = audio.loadSound(“media/picture.wav”);
local picture = display.newImageRect(“images/picture1.png”, 320, 88);
picture:setReferencePoint(display.CenterReferencePoint);
picture.x = display.stageWidth/2;
picture.y = 64;
function picture:touch(event)
if(event.phase == “ended”) then
audio.play(picture_sound);
local picture = display.newImageRect(“images/picture2.png”, 320, 88);
picture:setReferencePoint(display.CenterReferencePoint);
picture.x = display.stageWidth/2;
picture.y = 64;
end
end
picture:addEventListener(“touch”, picture);
– all objects must be added to group (e.g. self.view)
group:insert( bg )
group:insert ( picture )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– Do nothing
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene[/code] [import]uid: 150924 topic_id: 26876 reply_id: 326876[/import]
[import]uid: 150924 topic_id: 26876 reply_id: 109113[/import]