[solved] Remove image from view2

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]

In the ExitScene and destroyscene functions of View1.lua you should have to hide or remove ((or banish:)) the image from the scene. Now i don’t have corona installed in this computer because of it i can not write you the code.

If this one will not work you can purge the scene totaly while creating.
Like this:

on ExitScene function of of view1.lua write this code:
[lua]storyboard.purgeScene(“view2”) [/lua]

Hope this helps. I am also not so much advanced user:D [import]uid: 151402 topic_id: 26876 reply_id: 109083[/import]

@Talis Eldar, thanks for the help! But it don’t work… :frowning: [import]uid: 150924 topic_id: 26876 reply_id: 109113[/import]

Alwin can you please post here or some where your all lua codes i mean main.lua, view1.lua and view2.lua.

Because this solution that i post here is a working one that i am now using in my aplication.

As i said of course maybe it is not the optimized one but still working:D [import]uid: 151402 topic_id: 26876 reply_id: 109114[/import]

sure,

the main file

[code]-----------------------------------------------------------------------------------------

– main.lua


– show default status bar (iOS)
display.setStatusBar( display.DefaultStatusBar )

– include Corona’s “widget” library
local widget = require “widget”
local storyboard = require “storyboard”
– event listeners for tab buttons:
local function onFirstView( event )
storyboard.gotoScene( “view1” )
end

local function onSecondView( event )
storyboard.gotoScene( “view2” )
end
– create a tabBar widget with two buttons at the bottom of the screen

– table to setup buttons
local tabButtons = {
{ label=“view1”, up=“icon1.png”, down=“icon1-down.png”, width = 32, height = 32, onPress=onFirstView, selected=true },
{ label=“view2”, up=“icon2.png”, down=“icon2-down.png”, width = 32, height = 32, onPress=onSecondView },
}

– create the actual tabBar widget
local tabBar = widget.newTabBar{
top = display.contentHeight - 50, – 50 is default height for tabBar widget
buttons = tabButtons
}

onFirstView() – invoke first tab button’s onPress event manually[/code]

View2

[code]-----------------------------------------------------------------------------------------

– view2.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

– create some text
local title = display.newRetinaText( “Settings”, 0, 0, native.systemFont, 32 )
title:setTextColor( 0 ) – black
title:setReferencePoint( display.CenterReferencePoint )
title.x = display.contentWidth * 0.5
title.y = 125

– all objects must be added to group (e.g. self.view)
group:insert( bg )
group:insert( title )
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: 109115[/import]

Maybe the problem is “-- all objects must be added to group (e.g. self.view)”

group:insert( bg ) group:insert ( picture )

Perhaps something like this: ?

group:insert( bg ) group:insert ( picture ) Here a function ?
[import]uid: 150924 topic_id: 26876 reply_id: 109212[/import]

@ Talis Eldar

I have fixed the problem,

(director and localGroup:insert(groupname) will work [import]uid: 150924 topic_id: 26876 reply_id: 110883[/import]