How can I make that my image can only be exposed in main menu scene where I have “Addition” rectangle with questions when I open that but I just want to display that image on that rectangle and only on that scene(menu.lua) and when I use display.newImage it just displays that picture and if I go on other scene It stays there?
Are you using composer? If you are then add the image into a sceneGroup like this
sceneGroup:insert(imageName)
If you aren’t using composer then when you change scene’s do
display.remove(imageName)
Good Luck!
Sorry for the short not very good reply… I’m replying on my phone …
We would need to see some code to be sure what the issue is, but as Sonic says, it sounds like you’re using composer and forgetting to add the object to the scene’s group.
This is worth a read if you haven’t already:
https://coronalabs.com/blog/2014/01/21/introducing-the-composer-api-plus-tutorial/
I just downloaded quiz template and in that template there are sprite sheets which I don t know how to use it or how to make a sprite sheet for corona sdk so I just wanted to know how can I display a image on a rect which is disappearing when I choose some categorie. Lile games or music or something like that
Maybe this will help you out:
– main.lua
local composer = require "composer" composer.gotoScene("splash")
– splash.lua
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) background:setFillColor(1, 0, 0) local myText = display.newText("This is the splash screen.\nTap this text to change scene.", display.contentCenterX, display.contentCenterY) local function changeScene() composer.gotoScene("selection") end myText:addEventListener("tap", changeScene) -- all display objects must be inserted into the scenes group sceneGroup:insert(background) sceneGroup:insert(myText) end function scene:show( event ) end function scene:hide( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
– selection.lua
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) background:setFillColor(1, 0, 1) local gameTextBackground = display.newRoundedRect(display.contentCenterX, 100, 100, 50, 5) gameTextBackground:setFillColor(0.8, 0, 0) local musicTextBackground = display.newRoundedRect(display.contentCenterX, 200, 100, 50, 5) musicTextBackground:setFillColor(0.8, 0, 0) local backTextBackground = display.newRoundedRect(display.contentCenterX, 300, 100, 50, 5) backTextBackground:setFillColor(0.8, 0, 0) local gameText = display.newText("Games", gameTextBackground.x, gameTextBackground.y) local musicText = display.newText("Music", musicTextBackground.x, musicTextBackground.y) local backText = display.newText("Back", backTextBackground.x, backTextBackground.y) local function tapHandler(event) if event.target == gameTextBackground then print("You tapped 'Games'") -- composer.gotoScene("game") elseif event.target == musicTextBackground then print("You tapped 'Music'") -- composer.gotoScene("music") elseif event.target == backTextBackground then composer.gotoScene("splash") end end gameTextBackground:addEventListener("tap", tapHandler) musicTextBackground:addEventListener("tap", tapHandler) backTextBackground:addEventListener("tap", tapHandler) -- all display objects must be inserted into the scenes group sceneGroup:insert(background) sceneGroup:insert(gameTextBackground) sceneGroup:insert(gameText) sceneGroup:insert(musicTextBackground) sceneGroup:insert(musicText) sceneGroup:insert(backTextBackground) sceneGroup:insert(backText) end function scene:show( event ) end function scene:hide( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
Are you using composer? If you are then add the image into a sceneGroup like this
sceneGroup:insert(imageName)
If you aren’t using composer then when you change scene’s do
display.remove(imageName)
Good Luck!
Sorry for the short not very good reply… I’m replying on my phone …
We would need to see some code to be sure what the issue is, but as Sonic says, it sounds like you’re using composer and forgetting to add the object to the scene’s group.
This is worth a read if you haven’t already:
https://coronalabs.com/blog/2014/01/21/introducing-the-composer-api-plus-tutorial/
I just downloaded quiz template and in that template there are sprite sheets which I don t know how to use it or how to make a sprite sheet for corona sdk so I just wanted to know how can I display a image on a rect which is disappearing when I choose some categorie. Lile games or music or something like that
Maybe this will help you out:
– main.lua
local composer = require "composer" composer.gotoScene("splash")
– splash.lua
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) background:setFillColor(1, 0, 0) local myText = display.newText("This is the splash screen.\nTap this text to change scene.", display.contentCenterX, display.contentCenterY) local function changeScene() composer.gotoScene("selection") end myText:addEventListener("tap", changeScene) -- all display objects must be inserted into the scenes group sceneGroup:insert(background) sceneGroup:insert(myText) end function scene:show( event ) end function scene:hide( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
– selection.lua
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) background:setFillColor(1, 0, 1) local gameTextBackground = display.newRoundedRect(display.contentCenterX, 100, 100, 50, 5) gameTextBackground:setFillColor(0.8, 0, 0) local musicTextBackground = display.newRoundedRect(display.contentCenterX, 200, 100, 50, 5) musicTextBackground:setFillColor(0.8, 0, 0) local backTextBackground = display.newRoundedRect(display.contentCenterX, 300, 100, 50, 5) backTextBackground:setFillColor(0.8, 0, 0) local gameText = display.newText("Games", gameTextBackground.x, gameTextBackground.y) local musicText = display.newText("Music", musicTextBackground.x, musicTextBackground.y) local backText = display.newText("Back", backTextBackground.x, backTextBackground.y) local function tapHandler(event) if event.target == gameTextBackground then print("You tapped 'Games'") -- composer.gotoScene("game") elseif event.target == musicTextBackground then print("You tapped 'Music'") -- composer.gotoScene("music") elseif event.target == backTextBackground then composer.gotoScene("splash") end end gameTextBackground:addEventListener("tap", tapHandler) musicTextBackground:addEventListener("tap", tapHandler) backTextBackground:addEventListener("tap", tapHandler) -- all display objects must be inserted into the scenes group sceneGroup:insert(background) sceneGroup:insert(gameTextBackground) sceneGroup:insert(gameText) sceneGroup:insert(musicTextBackground) sceneGroup:insert(musicText) sceneGroup:insert(backTextBackground) sceneGroup:insert(backText) end function scene:show( event ) end function scene:hide( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene