Composer how to add object to scene from 2d array

Hi!

How to add object to scene from 2d Array?

local obj = {} for i = 1,3 do obj[i]= {} for j= 1,3 do  obj[i][j] = display.newRect(0, 0, 150, 50); scene:insert(obj[i][j]) end end 

That’s my try but doesn’t work

Please help.

Thanks in Advice

That should work, but are you sure you have a display group called scene? You need to insert the object into scene.view, or whatever you have used as a reference to scene.view.

The name is correct, unfortunately after going to the next stage, all other objects are removed. On stage stay only those obj from 2d array

Can you post all the code?

Well your code is drawing your rectangle’s on top of each other, so you can’t see any but the first.

Rob

Rubber duck debugging helps me a lot :slight_smile: this object was added correctly. Object created in other place isn’t insert to self.view

That should work, but are you sure you have a display group called scene? You need to insert the object into scene.view, or whatever you have used as a reference to scene.view.

The name is correct, unfortunately after going to the next stage, all other objects are removed. On stage stay only those obj from 2d array

Can you post all the code?

Well your code is drawing your rectangle’s on top of each other, so you can’t see any but the first.

Rob

Rubber duck debugging helps me a lot :slight_smile: this object was added correctly. Object created in other place isn’t insert to self.view