problem with storyboard duplicating objects

Hi,

I have a problem with storyboard, when I implement storyboard in one of my projects, two of the physical objects duplicate themselves (the rest of the objects stay fine).

The same project without storyboard works fine (no duplication).

Any help, please?

This is the code for one of the objects:

local indicator=display.newCircle( 100, 100, 20 )

–indicator:setReferencePoint(display.CenterReferencePoint)

indicator.x=200

indicator.y=0

physics.addBody(indicator,“dynamic”,{ density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 })

indicator.linearDamping = 0.5

group:insert(indicator)

–indicator.gravityScale = 0.75

indicator.isVisible=false

Where is this code getting executed? 

If it is in enterScene() or willEnterScene() AND if you don’t remove these objects when you leave the scene, they will get made again the next time you come back.

Likewise, if they are created in or as a result of the call to createScene() AND you are not giving them to the scene to control (i.e. not inserting them into the scene’s group, AND if you’re scene gets destroyed, then the next time you come back, they’ll get made again.  However, since the scene didn’t control them, it didn’t delete them last time and now you have two.

Whatever, the case, please show us the whole code snippet including the calls the scene callbacks like createScene(), enterScene(), etc.  The code above doesn’t give enough context to figure out the problem.

Also, if you can please use the code formatter (see the icon at the top of the editor like this: < > ). Your snippet is small and therefore legible, but if you drop a large bit of code it will be hard to read in text format.

-- Formatted code is easier to read and draws the eye&nbsp;

Cheers,

Ed

Well, all the code is being executed in

function scene:createScene( event)

enterScene() and willEnterScene() are being left empty.

This two lines outside of storyboard events on the top of the page:

local physics = require( “physics” )

physics.start()

The weird thing is that everything is working properly except this two duplicated objects.

I forgot to mention that this is not a problem of the objects not being purged. This happens when I enter the scene for the first time, and this objects only exist in this scene.

And, sorry, I forgot to include the code, note that the duplication occurs when the joystick is moved to control indicator.

local storyboard = require "storyboard" local scene = storyboard.newScene() local physics = require( "physics" ) physics.start() physics.setDrawMode( "hybrid" ) local indicator--- forward declaration, para que todos los events de storyboard los reconozcan local indicatorais ----1, aqui tiene que ir todo function scene:createScene( event ) local group = self.view ---comienzo de lo mio#############################################3 display.setStatusBar( display.HiddenStatusBar ) --https://github.com/roaminggamer/SSKCorona/wiki/ssk.inputs%3AcreateJoystick PARA EL JOYSTICK --physics.setGravity( 9, 0 ) --physics.setDrawMode( "debug" ) ----------------------))))))))))))))))))))))instrumentos(((((((((((((((((((((((((((((((((((((-------------------------------------------------- ----- PIRAMIDES para la logica de movimiento--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------- indicator=display.newCircle( 200, 170, 25 ) --indicator:setReferencePoint(display.CenterReferencePoint) physics.addBody(indicator,"dynamic",{ density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 }) indicator.linearDamping = 0.5 group:insert(indicator) --indicator.gravityScale = 0.75 indicator.isVisible=false --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE --local myRectangle = display.newRect(0,256, 500, 20) local myRectangle=display.newRect(0,200,500,20) physics.addBody(myRectangle,"static") myRectangle.isVisible=false group:insert(myRectangle) ------ PARA EL EJE Y''''''''''' local indicatory=display.newImage("indicator.png") indicatory:setReferencePoint(display.CenterReferencePoint) indicatory.x=205 indicatory.y=362 physics.addBody(indicatory,{densitiy=0.01,friction=3}) indicatory.isFixedRotation = true indicatory.gravityScale = 20 indicatory.isVisible=false group:insert(indicatory) --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE local myRectangley = display.newRect(0,356, 500, 20) physics.addBody(myRectangley,"static") myRectangley.isVisible=false group:insert(myRectangley) ------------para el tacometro------------------------ --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE para el ais de abajo local myRectanglet = display.newRect(-10,570, 500, 20) physics.addBody(myRectanglet,"static") myRectanglet.isVisible=false group:insert(myRectanglet) --------------para el ais------------ indicatorais=display.newCircle( 140, 535, 25 ) physics.addBody(indicatorais,{densitiy=200,friction=1,radius=25}) indicatorais.isVisible=false group:insert(indicatorais) -- FOR THE JOYSTICK ######################################################################################################### local StickLib = require("lib\_analog\_stick") local screenW = display.contentWidth local screenH = display.contentHeight local Text = display.newText( " ", screenW\*.6, screenH-20, native.systemFont, 15 ) -- CREATE A SPACE SHIP --local Ship = display.newGroup() --Ship.x = screenW \* .5 --Ship.y = screenH \* .5 --Tmp = display.newLine(-8,0, 8,0) --Tmp.width = 2 --Tmp:setColor (255,255,255, 255) --Tmp:append (0,-24, -8,0) --Ship:insert (Tmp) -- CREATE ANALOG STICK MyStick = StickLib.NewStick( { x = screenW\*.87, y = screenH\*.84, thumbSize = 16, borderSize = 92, snapBackSpeed = .75, R = 255, G = 255, B = 255 } ) --------------- -- MAIN LOOP local function main( event ) -- MOVE THE SHIP -- MyStick:move(Ship, 7.0, true) -- SHOW STICK INFO --Text.text = "ANGLE = "..MyStick:getAngle().." DISTANCE = "..math.ceil(MyStick:getDistance()).." PERCENT = "..math.ceil(MyStick:getPercent()\*100).."%" MyStick:movex( indicator, 3,false)--para mover la piramide MyStick:movey( indicatory, 3,false)-- para mover la otra piramide end Runtime:addEventListener( "enterFrame", main ) end ----2 function scene:enterScene( event ) local group = self.view --indicator.x=200 todo esto no es necesario ya que la x y la y la dices en create circle --indicator.y=170 --indicatorais.x=140 --inicialmente 0 idle --indicatorais.y=535 end ----3 function scene:exitScene( event ) end scene:addEventListener( "createScene" ) ----4 function scene:destroyScene( event ) print( "((destroying scene 1's view))" ) end -------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

Where is this code getting executed? 

If it is in enterScene() or willEnterScene() AND if you don’t remove these objects when you leave the scene, they will get made again the next time you come back.

Likewise, if they are created in or as a result of the call to createScene() AND you are not giving them to the scene to control (i.e. not inserting them into the scene’s group, AND if you’re scene gets destroyed, then the next time you come back, they’ll get made again.  However, since the scene didn’t control them, it didn’t delete them last time and now you have two.

Whatever, the case, please show us the whole code snippet including the calls the scene callbacks like createScene(), enterScene(), etc.  The code above doesn’t give enough context to figure out the problem.

Also, if you can please use the code formatter (see the icon at the top of the editor like this: < > ). Your snippet is small and therefore legible, but if you drop a large bit of code it will be hard to read in text format.

-- Formatted code is easier to read and draws the eye&nbsp;

Cheers,

Ed

Well, all the code is being executed in

function scene:createScene( event)

enterScene() and willEnterScene() are being left empty.

This two lines outside of storyboard events on the top of the page:

local physics = require( “physics” )

physics.start()

The weird thing is that everything is working properly except this two duplicated objects.

I forgot to mention that this is not a problem of the objects not being purged. This happens when I enter the scene for the first time, and this objects only exist in this scene.

And, sorry, I forgot to include the code, note that the duplication occurs when the joystick is moved to control indicator.

local storyboard = require "storyboard" local scene = storyboard.newScene() local physics = require( "physics" ) physics.start() physics.setDrawMode( "hybrid" ) local indicator--- forward declaration, para que todos los events de storyboard los reconozcan local indicatorais ----1, aqui tiene que ir todo function scene:createScene( event ) local group = self.view ---comienzo de lo mio#############################################3 display.setStatusBar( display.HiddenStatusBar ) --https://github.com/roaminggamer/SSKCorona/wiki/ssk.inputs%3AcreateJoystick PARA EL JOYSTICK --physics.setGravity( 9, 0 ) --physics.setDrawMode( "debug" ) ----------------------))))))))))))))))))))))instrumentos(((((((((((((((((((((((((((((((((((((-------------------------------------------------- ----- PIRAMIDES para la logica de movimiento--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------- indicator=display.newCircle( 200, 170, 25 ) --indicator:setReferencePoint(display.CenterReferencePoint) physics.addBody(indicator,"dynamic",{ density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 }) indicator.linearDamping = 0.5 group:insert(indicator) --indicator.gravityScale = 0.75 indicator.isVisible=false --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE --local myRectangle = display.newRect(0,256, 500, 20) local myRectangle=display.newRect(0,200,500,20) physics.addBody(myRectangle,"static") myRectangle.isVisible=false group:insert(myRectangle) ------ PARA EL EJE Y''''''''''' local indicatory=display.newImage("indicator.png") indicatory:setReferencePoint(display.CenterReferencePoint) indicatory.x=205 indicatory.y=362 physics.addBody(indicatory,{densitiy=0.01,friction=3}) indicatory.isFixedRotation = true indicatory.gravityScale = 20 indicatory.isVisible=false group:insert(indicatory) --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE local myRectangley = display.newRect(0,356, 500, 20) physics.addBody(myRectangley,"static") myRectangley.isVisible=false group:insert(myRectangley) ------------para el tacometro------------------------ --- BASE PARA EL ROZAMIENTO DE LA PIRAMIDE para el ais de abajo local myRectanglet = display.newRect(-10,570, 500, 20) physics.addBody(myRectanglet,"static") myRectanglet.isVisible=false group:insert(myRectanglet) --------------para el ais------------ indicatorais=display.newCircle( 140, 535, 25 ) physics.addBody(indicatorais,{densitiy=200,friction=1,radius=25}) indicatorais.isVisible=false group:insert(indicatorais) -- FOR THE JOYSTICK ######################################################################################################### local StickLib = require("lib\_analog\_stick") local screenW = display.contentWidth local screenH = display.contentHeight local Text = display.newText( " ", screenW\*.6, screenH-20, native.systemFont, 15 ) -- CREATE A SPACE SHIP --local Ship = display.newGroup() --Ship.x = screenW \* .5 --Ship.y = screenH \* .5 --Tmp = display.newLine(-8,0, 8,0) --Tmp.width = 2 --Tmp:setColor (255,255,255, 255) --Tmp:append (0,-24, -8,0) --Ship:insert (Tmp) -- CREATE ANALOG STICK MyStick = StickLib.NewStick( { x = screenW\*.87, y = screenH\*.84, thumbSize = 16, borderSize = 92, snapBackSpeed = .75, R = 255, G = 255, B = 255 } ) --------------- -- MAIN LOOP local function main( event ) -- MOVE THE SHIP -- MyStick:move(Ship, 7.0, true) -- SHOW STICK INFO --Text.text = "ANGLE = "..MyStick:getAngle().." DISTANCE = "..math.ceil(MyStick:getDistance()).." PERCENT = "..math.ceil(MyStick:getPercent()\*100).."%" MyStick:movex( indicator, 3,false)--para mover la piramide MyStick:movey( indicatory, 3,false)-- para mover la otra piramide end Runtime:addEventListener( "enterFrame", main ) end ----2 function scene:enterScene( event ) local group = self.view --indicator.x=200 todo esto no es necesario ya que la x y la y la dices en create circle --indicator.y=170 --indicatorais.x=140 --inicialmente 0 idle --indicatorais.y=535 end ----3 function scene:exitScene( event ) end scene:addEventListener( "createScene" ) ----4 function scene:destroyScene( event ) print( "((destroying scene 1's view))" ) end -------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene