HI, I’m fairly new to Corona and I’ve encountered a problem regarding the button and splash screen.
As soon as I run the file, a splash screen comes and there’s a button that you press to make the splash screen disappear. So far this has all gone well but the only problem is that the button stays. This is a problem. So I was wondering, how do I make it so that onPress of the button, the button AND the splash screen disappears? Thanks!
— splash screen?
local splashscreen = display.newImage( “ins.png” );
local function removeSplash( event )
splashscreen:removeSelf()
end
local removesplashbutton = widget.newButton{
width = 100,
height = 100,
defaultFile = “smallbutton.png”,
overFile = “button1.jpg”,
onPress = removeSplash,
}
Hi shlokzartsharma,
You’ll need to create an up-value reference to the button so you can access it in the removal function. Like so:
[lua]
local splashscreen = display.newImage( “ins.png” );
local removesplashbutton --up-value reference
local function removeSplash( event )
splashscreen:removeSelf()
removesplashbutton:removeSelf()
end
removesplashbutton = widget.newButton{
width = 100,
height = 100,
defaultFile = “smallbutton.png”,
overFile = “button1.jpg”,
onPress = removeSplash,
}
[/lua]
You may also want to use an “onRelease” listener instead of “onPress”, so all of this occurs after the user releases the button, instead of the moment the user touches the button. Up to your design preference I suppose.
Hope this helps,
Brent
Hi shlokzartsharma,
You’ll need to create an up-value reference to the button so you can access it in the removal function. Like so:
[lua]
local splashscreen = display.newImage( “ins.png” );
local removesplashbutton --up-value reference
local function removeSplash( event )
splashscreen:removeSelf()
removesplashbutton:removeSelf()
end
removesplashbutton = widget.newButton{
width = 100,
height = 100,
defaultFile = “smallbutton.png”,
overFile = “button1.jpg”,
onPress = removeSplash,
}
[/lua]
You may also want to use an “onRelease” listener instead of “onPress”, so all of this occurs after the user releases the button, instead of the moment the user touches the button. Up to your design preference I suppose.
Hope this helps,
Brent