Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Can someone explain how changing scene works ?
Started by filippo66627 Jan 28 2020 09:56 AM

16 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

Hi guys i dont understand how to switch scene. Every time i press the button that makes me go to another menu the previous menu doesn't disappear, well just some buttons. And if i want to go back to the previous menu it wont let me. Im a little bit confused  :huh:



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

All objects must be inserted into sceneGroup (scene.view) in order for Composer to remove them automatically. 



[TOPIC: post.html]
#3

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,473 posts
  • Corona SDK

Hi,

 

Take a look at the "Important" section here: https://docs.coronalabs.com/guide/system/composer/index.html#aboutscenes

 

-dev



[TOPIC: post.html]
#4

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

All objects must be inserted into sceneGroup (scene.view) in order for Composer to remove them automatically. 

like this ?

 local sceneGroup = self.view
 
local backgroundImage = .......
sceneGroup:insert(backgroundImage)
if it is it gives me an error


[TOPIC: post.html]
#5

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

Please be more specific. 'An error' doesn't mean anything, there are hundreds of possible errors and thousands of possible causes.



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

In the future, should download these two entire repositories:

For now... just download this:
 
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip 
 
 
Unzip it... then run the example in folder '5_frame'.  Once you have run it, go look at the file '5_frame/ifc/mainMenu.lua'
 
Pay close attention to how I deal with new display objects and how I place them in the scene group. 
 
The scene group manages these items, which is the problem you're running into (as others pointed out above).
 
 
Just for giggles, I'm pasting some code from the mainMenu.lua file here:


function scene:create( event )
   local sceneGroup = self.view

   -- Create a simple background
   local back = display.newImageRect( sceneGroup, "images/protoBack.png", 380*2, 570*2 )
   back.x = centerX
   back.y = centerY
   if(w>h) then back.rotation = 90 end

   -- Create a label showing which scene this is
   local label = display.newEmbossedText( sceneGroup, "Main Menu", centerX, 40, native.systemFont, 60 )
   label:setFillColor( 0xCC/255, 1, 1  )
   local color = 
   {
       highlight = { r=1, g=1, b=1 },
       shadow = { r=0, g=1, b=0.3 }
   }
   label:setEmbossColor( color )

   -- Create some buttons for navigation
   local playButton = PushButton( sceneGroup, centerX, centerY, "Play", onPlay, 
                             { labelColor = {0,1,0}, labelSize = 24 } )

   local optionsButton = PushButton( sceneGroup, centerX, centerY + 100, "Options", onOptions, 
                             { labelColor = {0,1,1}, labelSize = 24 } )

end


[TOPIC: post.html]
#7

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

 

In the future, should download these two entire repositories:

For now... just download this:
 
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip 
 
 
Unzip it... then run the example in folder '5_frame'.  Once you have run it, go look at the file '5_frame/ifc/mainMenu.lua'
 
Pay close attention to how I deal with new display objects and how I place them in the scene group. 
 
The scene group manages these items, which is the problem you're running into (as others pointed out above).
 
 
Just for giggles, I'm pasting some code from the mainMenu.lua file here:


function scene:create( event )
   local sceneGroup = self.view

   -- Create a simple background
   local back = display.newImageRect( sceneGroup, "images/protoBack.png", 380*2, 570*2 )
   back.x = centerX
   back.y = centerY
   if(w>h) then back.rotation = 90 end

   -- Create a label showing which scene this is
   local label = display.newEmbossedText( sceneGroup, "Main Menu", centerX, 40, native.systemFont, 60 )
   label:setFillColor( 0xCC/255, 1, 1  )
   local color = 
   {
       highlight = { r=1, g=1, b=1 },
       shadow = { r=0, g=1, b=0.3 }
   }
   label:setEmbossColor( color )

   -- Create some buttons for navigation
   local playButton = PushButton( sceneGroup, centerX, centerY, "Play", onPlay, 
                             { labelColor = {0,1,0}, labelSize = 24 } )

   local optionsButton = PushButton( sceneGroup, centerX, centerY + 100, "Options", onOptions, 
                             { labelColor = {0,1,1}, labelSize = 24 } )

end

sorry but i still don't get how you hide objects when switching scenes  :(



[TOPIC: post.html]
#8

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

You don't, Composer does, if you follow the instructions correctly.

[TOPIC: post.html]
#9

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

You don't, Composer does, if you follow the instructions correctly.

i don't know im still confused



[TOPIC: post.html]
#10

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

 

In the future, should download these two entire repositories:

For now... just download this:
 
https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip 
 
 
Unzip it... then run the example in folder '5_frame'.  Once you have run it, go look at the file '5_frame/ifc/mainMenu.lua'
 
Pay close attention to how I deal with new display objects and how I place them in the scene group. 
 
The scene group manages these items, which is the problem you're running into (as others pointed out above).
 
 
Just for giggles, I'm pasting some code from the mainMenu.lua file here:


function scene:create( event )
   local sceneGroup = self.view

   -- Create a simple background
   local back = display.newImageRect( sceneGroup, "images/protoBack.png", 380*2, 570*2 )
   back.x = centerX
   back.y = centerY
   if(w>h) then back.rotation = 90 end

   -- Create a label showing which scene this is
   local label = display.newEmbossedText( sceneGroup, "Main Menu", centerX, 40, native.systemFont, 60 )
   label:setFillColor( 0xCC/255, 1, 1  )
   local color = 
   {
       highlight = { r=1, g=1, b=1 },
       shadow = { r=0, g=1, b=0.3 }
   }
   label:setEmbossColor( color )

   -- Create some buttons for navigation
   local playButton = PushButton( sceneGroup, centerX, centerY, "Play", onPlay, 
                             { labelColor = {0,1,0}, labelSize = 24 } )

   local optionsButton = PushButton( sceneGroup, centerX, centerY + 100, "Options", onOptions, 
                             { labelColor = {0,1,1}, labelSize = 24 } )

end

cant i just add all my objects into a group and do

objGrp.isVisible = false
when switching scenes to hide the objects i don't need? 



[TOPIC: post.html]
#11

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

You can but this is just papering over another problem. Composer just works if you follow the API docs, in ten years making 50+ games I've never had an issue.

When something doesn't work in my projects and I lose sight of why, I rip out the code and start again, checking each and every line does what it should do before moving on.
  • roaminggamer likes this

[TOPIC: post.html]
#12

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

You can but this is just papering over another problem. Composer just works if you follow the API docs, in ten years making 50+ games I've never had an issue.

When something doesn't work in my projects and I lose sight of why, I rip out the code and start again, checking each and every line does what it should do before moving on.

so i did this

local objGrp=display.newGroup()
 
local cleanObj=function()
        objGrp:removeSelf()
        objGrp=nil
end
 
and added every object in this group like this 
local button1 = widget.newButton
 
{
  left = 35 ,
  top = 400 ,
  width = 22 ,
  height = 54,
  defaultFile = ("Sfondi/icons/1.png"),
  overFile = ("Sfondi/icons/1.png"),
  onEvent = handleButtonEvent1
} 
 objGrp:insert(button1)
the number disappears when i click on the other menu but when i get back to the first one it does not appear back ..


[TOPIC: post.html]
#13

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

Are you calling cleanObj when you leave the scene?

Composer has a few modes but by default, it will remove objects from the screen that are inserted into .view, but keep them in memory for when you return to the same scene. Therefore it does not 'redraw' everything so if you remove them yourself then nothing will appear. But without seeing all the code in context I'm just guessing what you're doing.

[TOPIC: post.html]
#14

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

Are you calling cleanObj when you leave the scene?

Composer has a few modes but by default, it will remove objects from the screen that are inserted into .view, but keep them in memory for when you return to the same scene. Therefore it does not 'redraw' everything so if you remove them yourself then nothing will appear. But without seeing all the code in context I'm just guessing what you're doing.

can i send you my code in pvt ?



[TOPIC: post.html]
#15

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

Sure, no problem. 

 

can i send you my code in pvt ?



[TOPIC: post.html]
#16

filippo66627

[GLOBAL: userInfoPane.html]
filippo66627
  • Enthusiast

  • 66 posts
  • Corona SDK

Sure, no problem. 

sent u a message, thank you 



[TOPIC: post.html]
#17

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,473 posts
  • Corona SDK

...

 
Just for giggles, I'm pasting some code from the mainMenu.lua file here:

 

I giggled.  :)

 

-dev




[topic_controls]
[/topic_controls]