Self copy object problem

Hi!
I have 2 Scene:

local storyboard = require "storyboard"  
local scene = storyboard.newScene()  
local physics = require("physics")  
physics.start()  
physics.setGravity( 0, 0 ) -- overhead view, therefore no splashGroupvity vector  
--physics.setDrawMode( "hybrid" )  
local btnplay, btncredits  
  
\_W = display.contentWidth  
\_H = display.contentHeight  
  
local ballBody = { density= .005, friction=.0, bounce=.5, radius =75 }  
--\>kolizja z pinem  
local PinAudio = audio.loadSound("\_sound/pin.mp3")   
--\> wskoczenie do dziury  
local PocketAudio = audio.loadSound("\_sound/pocket.mp3")   
function scene:createScene( event )  
local splashGroup = self.view  
  
  
 local splashBG = display.newImage("\_img/tlo1.png", true, 20, 1, true)  
 splashGroup:insert(splashBG)  
  
local lewo = display.newRect(0,0, -20, \_H)  
 splashGroup:insert(lewo)  
 lewo:setFillColor(0, 255, 255)  
 physics.addBody(lewo, "static")  
  
 local gora = display.newRect(0,0, \_W, 40)  
 splashGroup:insert(gora)  
 gora:setFillColor(255, 0, 255)  
 physics.addBody(gora, "static")  
  
 local dol = display.newRect(0,\_H, \_W, 0)  
 splashGroup:insert(dol)  
 dol:setFillColor(255, 0, 0)  
 physics.addBody(dol, "static")  
  
 local prawo = display.newRect(\_W,0, 20, \_H)  
 splashGroup:insert(prawo)  
 prawo:setFillColor(255, 0, 255)  
  
 physics.addBody(prawo, "static")  
function setCueball(x, y)  
 local cueball = display.newImage("\_img/pilka.png")  
 splashGroup:insert(cueball)  
 cueball.x = x  
 cueball.y = y  
  
 target = display.newImage( "\_img/target.png" )  
 splashGroup:insert(target)  
 target.x = cueball.x; target.y = cueball.y; target.alpha = 0;  
 physics.addBody( cueball, ballBody )  
 cueball.linearDamping = 0.3  
 cueball.angularDamping = 0.8  
 cueball.isBullet = true --   
 cueball.type = "cueBall"  
 cueball.collision = onCollision  
 cueball:addEventListener("collision", cueball) --   
 cueball.postCollision = ballCollisionAudio --  
 cueball:addEventListener( "postCollision", cueball )  
  
 cueball:addEventListener( "touch", cueShot )  
end  
  
function cueShot( event )  
  
 local t = event.target  
 local phase = event.phase  
  
  
  
 if "began" == phase then  
 display.getCurrentStage():setFocus( t )  
 t.isFocus = true  
  
 -- Stop current cueball motion, if any  
 t:setLinearVelocity( 0, 0 )  
 t.angularVelocity = 0  
  
 target.x = t.x  
 target.y = t.y  
  
 startRotation = function()  
 target.rotation = target.rotation + 4  
 end  
  
 Runtime:addEventListener( "enterFrame", startRotation )  
  
 local showTarget = transition.to( target, { alpha=0.4, xScale = 1.5, yScale= 1.5, time=200 } )  
 myLine = nil  
  
 elseif t.isFocus then  
  
 if "moved" == phase then  
  
 if ( myLine ) then  
 myLine.parent:remove( myLine ) -- erase previous line, if any  
 end  
 myLine = display.newLine( t.x,t.y, event.x,event.y )  
 myLine:setColor( 255, 255, 255, 50 )  
 myLine.width = 15  
 elseif "ended" == phase or "cancelled" == phase then  
  
 display.getCurrentStage():setFocus( nil )  
 t.isFocus = false  
  
 local stopRotation = function()  
 Runtime:removeEventListener( "enterFrame", startRotation )  
 end  
  
 local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )  
  
 if ( myLine ) then  
 myLine.parent:remove( myLine )  
 end  
  
 t:applyForce( (event.x - t.x ), (event.y - t.y ) ,t.x , t.y )   
 end  
  
 end   
 return true   
end  
  
local function onCollision( event )  
  
 if ( event.phase == "began" ) then  
  
 elseif ( event.phase == "ended" ) then  
  
 if (event.object1.myName == "play") then  
  
 audio.play(PinAudio)  
  
 storyboard.gotoScene( "menulv", "crossFade", 200 )  
 event.object2:removeSelf()  
 elseif (event.object1.myName == "credits") then  
  
 audio.play(PinAudio)  
 --event.object2:removeSelf()  
 storyboard.purgeScene("menu")  
 end  
  
 end  
end  
  
 btnplay = display.newImage( "\_img/graj.png", 550, 200, true)   
 splashGroup:insert(btnplay)  
 btnplay.myName = "play"  
 physics.addBody(btnplay, "static")  
  
 btncredits = display.newImage( "\_img/credits.png", 550,500, true)   
 splashGroup:insert(btncredits)  
 physics.addBody(btncredits, "static")  
 btncredits.myName = "credits"  
  
  
 storyboard.Tries = 0  
 storyboard.Pins = 0  
  
 Runtime:addEventListener( "collision", onCollision )   
  
end  
  
function scene:enterScene( event )  
 storyboard.purgeAll()  
 setCueball(100,\_H/2)   
end  
  
function scene:exitScene( event )  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
  
end  
  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
scene:addEventListener( "createScene", scene )  
  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
  
return scene  

and:

local physics = require("physics")  
physics.start()  
physics.setGravity( 0, 0 )  
physics.setDrawMode( "hybrid" )  
local storyboard = require "storyboard"  
local scene = storyboard.newScene()  
\_W = display.contentWidth  
\_H = display.contentHeight  
local ballBody = { density= .005, friction=.0, bounce=.5, radius =75 }  
local function lev1( self, event )  
 if event.phase == "began" then  
  
 storyboard.purgeAll()  
 storyboard.gotoScene( "menu", "crossFade", 200 )  
  
 return true  
 end  
end  
function scene:createScene( event )  
  
 local splashGroup = self.view  
 --splashGroup = display.newGroup()  
  
 local splashBG = display.newImage("\_img/tlo1.png", true, 20, 1, true)  
 splashGroup:insert(splashBG)  
  
 w1 = display.newImage( "\_img/menulv/1.png",20, \_H/2-75, true)  
 w1.myName = "w1"  
 physics.addBody(w1, "static")  
 w1.touch = lev1  
 local lewo = display.newRect(0,0, -20, \_H)  
 splashGroup:insert(lewo)  
 lewo:setFillColor(0, 255, 255)  
 physics.addBody(lewo, "static")  
  
 local gora = display.newRect(0,0, \_W, 40)  
 splashGroup:insert(gora)  
 gora:setFillColor(255, 0, 255)  
 physics.addBody(gora, "static")  
  
 local dol = display.newRect(0,\_H, \_W, 0)  
 splashGroup:insert(dol)  
 dol:setFillColor(255, 0, 0)  
 physics.addBody(dol, "static")  
  
 local prawo = display.newRect(\_W,0, 20, \_H)  
 splashGroup:insert(prawo)  
 prawo:setFillColor(255, 0, 255)  
  
 physics.addBody(prawo, "static")  
  
function setCueball(x, y)  
 local cueball = display.newImage("\_img/pilka.png")  
 splashGroup:insert(cueball)  
 cueball.x = x  
 cueball.y = y  
  
 target = display.newImage( "\_img/target.png" )  
 splashGroup:insert(target)  
 target.x = cueball.x; target.y = cueball.y; target.alpha = 0;  
  
 physics.addBody( cueball, ballBody )  
 cueball.linearDamping = 0.3  
 cueball.angularDamping = 0.8  
 cueball.isBullet = true --   
 cueball.type = "cueBall"  
 cueball.collision = onCollision  
 cueball:addEventListener("collision", cueball) --   
 cueball.postCollision = ballCollisionAudio --  
 cueball:addEventListener( "postCollision", cueball )  
  
 cueball:addEventListener( "touch", cueShot )  
end  
  
function cueShot( event )  
  
 local t = event.target  
 local phase = event.phase  
  
  
  
 if "began" == phase then  
 display.getCurrentStage():setFocus( t )  
 t.isFocus = true  
  
 -- Stop current cueball motion, if any  
 t:setLinearVelocity( 0, 0 )  
 t.angularVelocity = 0  
  
 target.x = t.x  
 target.y = t.y  
  
 startRotation = function()  
 target.rotation = target.rotation + 4  
 end  
  
 Runtime:addEventListener( "enterFrame", startRotation )  
  
 local showTarget = transition.to( target, { alpha=0.4, xScale = 1.5, yScale= 1.5, time=200 } )  
 myLine = nil  
  
 elseif t.isFocus then  
  
 if "moved" == phase then  
  
 if ( myLine ) then  
 myLine.parent:remove( myLine ) -- erase previous line, if any  
 end  
 myLine = display.newLine( t.x,t.y, event.x,event.y )  
 myLine:setColor( 255, 255, 255, 50 )  
 myLine.width = 15  
 elseif "ended" == phase or "cancelled" == phase then  
  
 display.getCurrentStage():setFocus( nil )  
 t.isFocus = false  
  
 local stopRotation = function()  
 Runtime:removeEventListener( "enterFrame", startRotation )  
 end  
  
 local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )  
  
 if ( myLine ) then  
 myLine.parent:remove( myLine )  
 end  
  
 -- plus na minus  
 t:applyForce( (event.x - t.x ), (event.y - t.y ) ,t.x , t.y )   
 end  
  
 end   
 return true -- Stop further propagation of touch event  
end  
  
local function onCollision( event )  
  
 if ( event.phase == "began" ) then  
  
 elseif ( event.phase == "ended" ) then  
 --audio.play(PinAudio)  
 if (event.object1.myName == "w1") then  
  
 audio.play(PinAudio)  
 --storyboard.purgeScene("menu")  
 storyboard.gotoScene( "level1", "crossFade", 200 )  
 event.object2:removeSelf()  
 elseif (event.object1.myName == "options") then  
  
  
 audio.play(PinAudio)  
 --storyboard.purgeScene("menu")  
  
 storyboard.gotoScene( "options", "crossFade", 200 )  
 event.object2:removeSelf()  
 elseif (event.object1.myName == "credits") then  
  
 audio.play(PinAudio)  
 --storyboard.purgeScene("menu")  
 end  
  
 end  
end  
  
Runtime:addEventListener( "collision", onCollision )   
end  
  
function scene:enterScene( event )  
  
 storyboard.removeAll()  
 storyboard.purgeAll()  
 setCueball(\_W/2 + 200,\_H/2)  
 w1:addEventListener("touch", w1)  
end  
  
function scene:exitScene( event )  
  
 Runtime:removeEventListener( "collision", onCollision )   
 w1:removeEventListener( "touch", w1 )  
end  
  
function scene:destroyScene( event )  
  
end  
  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
scene:addEventListener( "createScene", scene )  
  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
  
return scene  
  

When i go first time to second scene every thing is ok, when i back every thing is ok second time go from first scene to second is ok, but when i back and start my ball start moving they copy. when i go to second screen now i have 2 balls. Every that kind loop give me 1 more ball. What i do wrong?
In advance
Thanks for yours time [import]uid: 117910 topic_id: 35540 reply_id: 335540[/import]

Do you add your cueball to your splashGroup?
[import]uid: 199310 topic_id: 35540 reply_id: 141273[/import]

m_zap, would you mind posting a zip of the full project… You’re likely to get a much quicker answer if it’s easier to run to find the error. [import]uid: 72364 topic_id: 35540 reply_id: 141277[/import]

@Rob Miracle
Yes CueBall was added to splashGroup
@ScottPhillips
There is my problem:)
http://www.speedyshare.com/MhAsK/Game.7z [import]uid: 117910 topic_id: 35540 reply_id: 141316[/import]

Do you add your cueball to your splashGroup?
[import]uid: 199310 topic_id: 35540 reply_id: 141273[/import]

m_zap, would you mind posting a zip of the full project… You’re likely to get a much quicker answer if it’s easier to run to find the error. [import]uid: 72364 topic_id: 35540 reply_id: 141277[/import]

@Rob Miracle
Yes CueBall was added to splashGroup
@ScottPhillips
There is my problem:)
http://www.speedyshare.com/MhAsK/Game.7z [import]uid: 117910 topic_id: 35540 reply_id: 141316[/import]