Can't remove Object, easiest example

Hi,

i do this hundred times, is late but i can’t go sleep fithout answer.

I generate multiscreen default projekt edit scene1.lua

to

local physics = require("physics") physics.start() physics.setGravity( 0, 0 ); physics.setDrawMode("hybrid"); local composer = require( "composer" ) local scene = composer.newScene( ) function myRectTouch()     composer.gotoScene("scene2") end function createObj()     local myRectangle = display.newRect( 0, 0, 150, 50 );     myRectangle:addEventListener("touch", myRectTouch)     sceneGroup:insert(myRectangle);     physics.addBody( myRectangle, "dynamic", {radius = 50} ); end function scene:create( event )     sceneGroup = self.view     createObj(); end function scene:show( event )     local sceneGroup = self.view     local phase = event.phase     if phase == "will" then     elseif phase == "did" then             end end function scene:hide( event )     local sceneGroup = self.view     local phase = event.phase     if event.phase == "will" then     elseif phase == "did" then     end end function scene:destroy( event )     local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

body stil displaing on scene 2 ;(

why and how to repair this

Hi @m_zap,

It appears that you’re not properly managing and referencing the “sceneGroup” variable. It’s not properly scoped in all of your scene functions (create, show, etc.). Also, you reference it in the “createObj” function, but it’s not valid there, because you didn’t upvalue it. I would actually suggest that you pass the scene view as an argument to the “createObj” function, so Corona always knows which display group you’re dealing with in that function.

Take care,

Brent

Also, avoid using global functions. Global = bad!

Brent

i change to:

local function myRectTouch()     composer.gotoScene("scene2") end local function createObj(view)     local myRectangle = display.newRect( 0, 0, 150, 50 );     myRectangle:addEventListener("touch", myRectTouch)     view:insert(myRectangle);     physics.addBody( myRectangle, "dynamic", {radius = 50} ); end function scene:create( event )     local sceneGroup = self.view     createObj(sceneGroup); end

result was the same

Hi @m_zap,

It appears that you’re not properly managing and referencing the “sceneGroup” variable. It’s not properly scoped in all of your scene functions (create, show, etc.). Also, you reference it in the “createObj” function, but it’s not valid there, because you didn’t upvalue it. I would actually suggest that you pass the scene view as an argument to the “createObj” function, so Corona always knows which display group you’re dealing with in that function.

Take care,

Brent

Also, avoid using global functions. Global = bad!

Brent

i change to:

local function myRectTouch()     composer.gotoScene("scene2") end local function createObj(view)     local myRectangle = display.newRect( 0, 0, 150, 50 );     myRectangle:addEventListener("touch", myRectTouch)     view:insert(myRectangle);     physics.addBody( myRectangle, "dynamic", {radius = 50} ); end function scene:create( event )     local sceneGroup = self.view     createObj(sceneGroup); end

result was the same